Fixing quote escaping in backreference replacements : Quotation « String « PHP






Fixing quote escaping in backreference replacements

 
<?php
$html = "<code>&lt;b&gt; It's bold &lt;/b&gt;</code>";
print preg_replace('@<code>(.*?)</code>@e',"preg_html_entity_decode('$1')", $html);
print "\n";

$html = '<code>&lt;i&gt; "This" is italic. &lt;/i&gt;</code>';
print preg_replace('@<code>(.*?)</code>@e',"preg_html_entity_decode('$1')", $html);
print "\n";

function preg_html_entity_decode($s) {
    $s = str_replace('\\"','"', $s);
    return html_entity_decode($s);
}
?>
  
  








Related examples in the same category

1.Double quotation marks allow the parsing of variables
2.Double-quoted string escape sequences
3.Double-quoted strings
4.If you use single quotation marks to enclose the same string, the variable is not substituted:
5.Using forward slashes on Windows
6.It is safe to use non-escaped Windows-style filenames in your single-quoted strings
7.Various special characters in string assignments