php - How to stop preg_replace() returning numerical references? -
i'm using preg_replace()
perform regular expression search , replace.
$string = "this isn't real string example."; $result = preg_replace($pattern, $replacement, $string); echo $result; // isn’t real string example.
as can see, $string
contains single quote. regardless of whether match found, when output return value of preg_replace()
, single quote becomes ’
how can stop preg_replace()
returning numerical references such ’
? need string keep single quote character.
update
here's pattern:
$pattern = '/#(\w+)/';
update 2
here's replacement string:
$replacement = '<a href="https://example.com/tag/$1/">#$1</a>';
you can try using html_entity_decode()
achieve that
here snippet
$string = "this isn't real string example."; $result = preg_replace($pattern, $replacement, $string); echo html_entity_decode($result); // isn't real string example.
Comments
Post a Comment