This question already has an answer here:
so I did
$subject = 'sakdlfjsalfdjslfad <a href="something/8230">lol is that true?</a> lalalala';
$subject = preg_replace('<a href="something\/([0-9]+)">(.+?)<\/a>', '$1', $subject);
echo $subject;
whereby the objective is to have $subject return
'sakdlfjsalfdjslfad lol is that true? lalalala'
but then PHP returned
warning: preg_replace(): Unknown modifier '('
what did I do wrong?
</div>
the pattern needs delimiters -- slashes, e.g.
'/<a href="something\/([0-9]+)">(.+?)<\/a>/'
You need delimiters around the pattern:
$subject = preg_replace('#<a href="something/([0-9]+)">(.+?)</a>#', '$1', $subject);
A PCRE (Perl Compatible Regular Expression) should be surrounded by delimiters, so
<a href="something\/([0-9]+)">(.+?)<\/a>
should be
/<a href="something\/([0-9]+)">(.+?)<\/a>/
I have used slashes (/
) - but there are lots of choices
When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.
Often used delimiters are forward slashes (/), hash signs (#) and tildes (~). The following are all examples of valid delimited patterns.