N
N
Name2018-03-09 05:20:30
PHP
Name, 2018-03-09 05:20:30

Replace in text but skip replacement in tags?

There is a code like this replaces once in the text:

function str_replace_once($search, $replace, $text) 
{ 
$pos = strpos($text, $search); 
return $pos!==false ? substr_replace($text, $replace, $pos, strlen($search)) : $text; 
}

$str = 'Helo World!'; 
$str = str_replace_once('l', 'll', $str); 
// результат 'Hello World!';

tell me how to add exceptions to the conditions so that replacements do not occur if the text is in tags
, that is, if
$str = '<a href="(тут любая ссылка)">Helo World!</a>';

then the substitution will not take place.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-03-09
@BorisKorobkov

https://code.google.com/archive/p/phpquery/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question