Jump to content

Simple preg_replace Help Please!


JJ2K

Recommended Posts

Hi,

 

I have a link like this:

 

<a href="myword.php" title="myword">some other text myword blah foo</a>

 

OK now I need to replace myword with newword, but only in the anchor text. So myword in the href or title should not be changed, only matches found inside the anchor text!

 

I tried using str_replace but obviously this just matched all occurances. So I guess preg_replace is the way to go here but it is far too advanced for me and I cannot get my head around all the different symbols.

 

Here is some example code:

 

$html = '<a href="myword.php" title="myword">some other text myword blah foo</a>';
$new = 'newword'
$html = preg_replace(//unsure here!);

 

I just don't know how to work regex  :shrug: OT: Did you find it easy/difficult to learn? Thanks to any help :)

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.