替换HTML中的单个单词,但不替换链接内的单词

I have a piece of HTML and want to replace a particular word.

For example: This is Test -> This is egegeg

But I don't want to replace it inside links (<a href=...) and image links (<img src=...).

How can I solve this?

To do this you would use str_replace:

$string = 'This is a test';
$newString = str_replace('test', 'egegeg', $string);
echo $newString;
// This is a egegeg

It works by passing in what you are looking for (test), what to replace it with (egegeg) and what string to search.

More details can be found on the PHP website - http://php.net/manual/en/function.str-replace.php

Search, find and replace.

$string = 'My awesome dude';
$replace = str_replace('awesome', 'bald', $string);

echo $replace;