|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-09-16 12:02 UTC] jani@php.net
[2009-09-24 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 16:00:02 2025 UTC |
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"