Doc #60401 [NEW]: Example 4 results in double quotes slashed
| From: | jf at jonathanfoote dot com | Date: | Mon, 28 Nov 2011 06:32:45 +0000 |
| Subject: | Doc #60401 [NEW]: Example 4 results in double quotes slashed | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-7482@lists.php.net to get a copy of this message | ||
From:
Operating system: Windows
PHP version: 5.3.8
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Example 4 results in double quotes slashed
Description:
------------
---
From manual page: http://www.php.net/function.preg-replace
---
Example #4 from preg_replace() it states:
This would capitalize all HTML tags in the input text.
But it does not mention that double quotes would get slashes added. Using
the
example would result in the text:
<div class="test">
to be converted to:
<DIV class=\"test\">
The tag is indeed converted to uppercase as it states, but slashes are
added to
double quotes. See below for perhaps a more robust example that accounts
for
this (basically run the rest through str_replace() that replaces \" with
").
Test script:
---------------
<?php
$html_body = '<div class="test">';
//Solution from example #4
$html_upper = preg_replace("/(<\/?)(\w+)([^>]*>)/e",
"'\\1'.strtoupper('\\2').'\\3'",
$html_body);
echo $html_upper;
//resulted output: <DIV class=\"test\">
//Better solution:
$html_upper = preg_replace("/(<\/?)(\w+)([^>]*>)/e",
"'\\1'.strtoupper('\\2').str_replace('\\\"','\"','\\3')",
$html_body);
echo $html_upper;
//resulted output: <DIV class="test">
?>
--
Edit bug report at https://bugs.php.net/bug.php?id=60401&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60401&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60401&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60401&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=60401&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60401&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=60401&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=60401&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=60401&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=60401&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=60401&r=support
Expected behavior: https://bugs.php.net/fix.php?id=60401&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=60401&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=60401&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=60401&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60401&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=60401&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=60401&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=60401&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=60401&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=60401&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=60401&r=mysqlcfg