Jump to content

[SOLVED] Truncating a string after a found string inside of that string.


jlange

Recommended Posts

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
Share on other sites

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
Share on other sites

$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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.