jlange Posted July 14, 2007 Share Posted July 14, 2007 I'm not sure how to do this. What I'm trying to do is this: turn this: <a href="somelink"><img src="imgsrc" height="y" width="x">Some nonstatic text, courtesy of Flickr</a> into this: <a href="somelink"><img src="imgsrc" style="mystyle"></a> thoughts? Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/ Share on other sites More sharing options...
jlange Posted July 14, 2007 Author Share Posted July 14, 2007 by the way, i figured i can use a string search function to find a value from an array i'll make that will have all the different kinds of image file extensions, so, is there a string function to find what character number that is, or something? then, i could truncate it after that number of characters then just add on my string to the end. Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/#findComment-298280 Share on other sites More sharing options...
AndyB Posted July 14, 2007 Share Posted July 14, 2007 strpos() - http://ca.php.net/manual/en/function.strpos.php Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/#findComment-298283 Share on other sites More sharing options...
ToonMariner Posted July 14, 2007 Share Posted July 14, 2007 regular expression is the answer. $str = <a href="somelink"><img src="imgsrc" height="y" width="x">Some nonstatic text, courtesy of Flickr</a>'; $str = preg_replace('/(<a(.)*?>)<img(.)*?>(.)*?<\/a>/','$1$3</a>',$str); try that.. Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/#findComment-298285 Share on other sites More sharing options...
jlange Posted July 14, 2007 Author Share Posted July 14, 2007 ToonMariner: That gave me all of that extraneous text, and no image! i'll do some research on that function though, because to me it just looks like compiled C... Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/#findComment-298289 Share on other sites More sharing options...
jlange Posted July 14, 2007 Author Share Posted July 14, 2007 $stringpos = strpos($content, '.jpg'); $stringpos = $stringpos+4; $chars = $stringpos; $content = substr($content,0,$stringpos); $content = $content."\" style=\"height:100px\" /></a>"; works! thanks! Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/#findComment-298299 Share on other sites More sharing options...
ToonMariner Posted July 14, 2007 Share Posted July 14, 2007 sorry didn't etst it out first!!!! try this... $str = '<a href="somelink"><img src="imgsrc" height="y" width="x">Some nonstatic text, courtesy of Flickr</a>'; $str = preg_replace('/(<a(.)*?><img(.)*?>)(.)*?<\/a>/','$1</a>',$str); echo $str; Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/#findComment-298447 Share on other sites More sharing options...
jlange Posted July 15, 2007 Author Share Posted July 15, 2007 Thanks, solved! Link to comment https://forums.phpfreaks.com/topic/59972-solved-truncating-a-string-after-a-found-string-inside-of-that-string/#findComment-298541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.