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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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.. Quote Link to comment 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... Quote Link to comment 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! Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
jlange Posted July 15, 2007 Author Share Posted July 15, 2007 Thanks, solved! Quote Link to comment 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.