ID: 49569 Updated by: [email protected] Reported By: thespiraloflife at hotmail dot com -Status: Open +Status: Feedback -Bug Type: Regexps related +Bug Type: PCRE related Operating System: linux PHP Version: 5.2.10 New Comment:
Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. You do know about this: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php And that PCRE != Perl? Previous Comments: ------------------------------------------------------------------------ [2009-09-16 10:42:43] thespiraloflife at hotmail dot com Description: ------------ preg_replace has a bug //CASE STUDY: remove multiple instances of inside <table> <div id="Paginator"> <span></span> <a href="#"></a> </div></table> $m = "¬";//Any marker that isn't currently in the strHTML string. Note, this is an example, but you should use a function that gets a safeMarker. // replaces all instances of </table> with </table>¬ $strHTML = preg_replace('/(<\/table>)/','$1'.$m, $strHTML); //looks for all within <table><div id="Paginator"> and removes them //This would be the code to use but php seems to be greedy and doesn't match all instances and only gets the last , where as perl, .NET or javascript regular expressions would $strHTML = preg_replace('/(\<div\sid\=\"Paginator\"\>[^\¬]*)\&nbps\;/','$1', $strHTML); Reproduce code: --------------- --- >From manual page: function.preg-replace --- //CASE STUDY: remove multiple instances of inside <table> <div id="Paginator"></div></table> $m = "¬";//Any marker that isn't currently in the strHTML string. Note, this is an example, but you should use a function that gets a safeMarker. // replaces all instances of </table> with </table>¬ $strHTML = preg_replace('/(<\/table>)/','$1'.$m, $strHTML); //looks for all within <div id="Paginator"> and removes them //This would be the code to use but php seems to be greedy and doesn't match all instances and only gets the last , where as perl, .NET or javascript regular expressions would $strHTML = preg_replace('/(\<div id\=\"Paginator\"\>[^\¬]*)\&nbps\;/','$1', $strHTML); Expected result: ---------------- Would remove all instances of inside <div id="Paginator" Actual result: -------------- Only removes the last &nbps; inside <div id="Paginator" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49569&edit=1
