Mutley Posted November 22, 2009 Share Posted November 22, 2009 There is probably a better way of doing this but the problem I'm having is it puts the images at the top of the page (before EVERYTHING else). The PHP is in a loop, so it looks at 5 different strings then echos the image. here's my code ($r['content'] being the string it looks for the image). Funtion: <php> ob_start(); function bm_extract_string($start, $end, $original) { $original = stristr($original, $start); $trimmed = stristr($original, $end); return substr($original, strlen($start), -strlen($trimmed)); } </php> Echo bit (this is in a loop): <php> $content = $r['content']; $pic_string = bm_extract_string("src='","' ",$content); echo '<img src="'.$pic_string.'" />'; </php> Any ideas? I don't think the page code will make much sense as it's IPB3 but here it is: <php> ob_start(); function bm_extract_string($start, $end, $original) { $original = stristr($original, $start); $trimmed = stristr($original, $end); return substr($original, strlen($start), -strlen($trimmed)); } </php> <script type='text/javascript'> Event.observe( window, 'load', function(){ // Resize images $$('.hentry').each( function(elem){ ipb.global.findImgs( $( elem ) ); }); }); </script> <ul class='hfeed'> <if test="is_array( $records ) && count( $records )"> {parse striping="feed_striping"} <foreach loop="$records as $r"> <li style="padding:10px" class='hentry {parse striping="feed_striping"}'> <php> $content = $r['content']; $pic_string = bm_extract_string("src='","' ",$content); echo '<img src="'.$pic_string.'" />'; </php> <a href='{$r['url']}' rel='bookmark' title='{$r['title']}'><h2 style="font-size:24px; font-weight:bold; margin-bottom:0px; border-bottom:1px #284B72 solid; width:100%">{$r['title']}</h2></a> <div style="float:left; padding-top:2px"> <div class="addthis_toolbox addthis_default_style"> <a href="http://www.addthis.com/bookmark.php?v=250&pub=xa-4b08040306d7ea55" class="addthis_button_expanded">Share</a> <span class="addthis_separator">|</span> <a class="addthis_button_digg"></a> <a class="addthis_button_twitter"></a> <a class="addthis_button_reddit"></a> <a class="addthis_button_delicious"></a> <a class="addthis_button_favorites"></a> <a class="addthis_button_print"></a> </div> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pub=xa-4b08040306d7ea55"></script> </div> <span style="float:right; font-size:11px; font-weight:bold; color:#000066"> <img src="files/comments.gif" alt="" /> <a href='{$r['url']}' rel='bookmark' title='{$r['title']}'>{$r['topic_posts']} comment<if test="$r['topic_posts'] > 1">s</if></a> | <b><abbr class="published" title="{parse expression="date( 'c', $r['date'] )"}">{parse date="$r['date']" format="short"}</b></abbr> </span> <br /><br /> <div class='desctext' style="padding-left:25px">{$r['content']} </div> </li> <br /> </foreach> </if> </ul> <br /><br /> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/182555-get-first-image-in-string-function-issue/ Share on other sites More sharing options...
Mutley Posted November 23, 2009 Author Share Posted November 23, 2009 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/182555-get-first-image-in-string-function-issue/#findComment-963904 Share on other sites More sharing options...
sasa Posted November 23, 2009 Share Posted November 23, 2009 try <?php function bm_extract_string($start, $end, $original) { $original1 = stristr($original, $start); $trimmed = stristr($original, $end); return substr($original, $origil1+strlen($start), $trimmed-$original1-strlen($start)); } $content = $r['content']; $pic_string = bm_extract_string("src='","' ",$content); echo '<img src="'.$pic_string.'" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/182555-get-first-image-in-string-function-issue/#findComment-963909 Share on other sites More sharing options...
Mutley Posted November 23, 2009 Author Share Posted November 23, 2009 try <?php function bm_extract_string($start, $end, $original) { $original1 = stristr($original, $start); $trimmed = stristr($original, $end); return substr($original, $origil1+strlen($start), $trimmed-$original1-strlen($start)); } $content = $r['content']; $pic_string = bm_extract_string("src='","' ",$content); echo '<img src="'.$pic_string.'" />'; ?> No, that didn't work either. Quote Link to comment https://forums.phpfreaks.com/topic/182555-get-first-image-in-string-function-issue/#findComment-963920 Share on other sites More sharing options...
sasa Posted November 23, 2009 Share Posted November 23, 2009 ups <?php function bm_extract_string($start, $end, $original) { $original1 = stripos($original, $start); $trimmed = stripos($original, $end); return substr($original, $original1+strlen($start), $trimmed-$original1-strlen($start)); } $content = $r['content']; $pic_string = bm_extract_string("src='","' ",$content); echo '<img src="'.$pic_string.'" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/182555-get-first-image-in-string-function-issue/#findComment-964129 Share on other sites More sharing options...
Mutley Posted November 23, 2009 Author Share Posted November 23, 2009 Is that just with the spelling corrections? I spotted those and fixed them before. But sadly it didn't work either. I don't know why, it just seems to be dumping PHP at the very top of the page. Even if I don't use a function to do the job. Quote Link to comment https://forums.phpfreaks.com/topic/182555-get-first-image-in-string-function-issue/#findComment-964137 Share on other sites More sharing options...
sasa Posted November 23, 2009 Share Posted November 23, 2009 i try this code <?php function bm_extract_string($start, $end, $original) { $original1 = stripos($original, $start); $trimmed = stripos($original, $end); return substr($original, $original1+strlen($start), $trimmed-$original1-strlen($start)); } //$content = $r['content']; $content = "bla bla bla src='picture.bmp' bla bla"; $pic_string = bm_extract_string("src='","' ",$content); echo '<img src="'.$pic_string.'" />'; ?> and it outputs <img src="picture.bmp" /> Quote Link to comment https://forums.phpfreaks.com/topic/182555-get-first-image-in-string-function-issue/#findComment-964173 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.