Jump to content

Extract <a> from string


fraser5002

Recommended Posts

Hi i have a string which contains some text and 2 links for example. 

 

How could i extract all the string minus one of the links

 

eg  $textstring = "some text before <a href="testpage.php"> <img src="image1.jpg" /></a> <a href="testpage2.php"> <img src="image2.jpg" /></a> some text after "

 

 

i would like to make a create a new string which contains all this text minus the first link

 

$newstring = "some text before <a href="testpage2.php"> <img src="image2.jpg" /></a> some text after "

 

 

any ideas?

Link to comment
Share on other sites

hi thanks the the reply it nearly works for me but i run into a problem when the <a is not separated by a space from the characters before it

 

i.e sometext<a href="blabla.php"> link1</a>

 

it does not seem to be able to pick up that first <a> tag and im assuming its because there is no space between the text and the start of the <a

 

is this right?

 

Thanks

Fraser

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.