note 50931 added to function.preg-match

From: Date: Mon, 14 Mar 2005 11:57:30 +0000
Subject: note 50931 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-86397@lists.php.net to get a copy of this message
The ExtractString function does not have a real error, but some disfunction. What if is called like this: ExtractString($row, 'action="', '"'); It would find 'action="' correctly, but perhaps not the first " after the $start-string. If $row consists of <form method="post" action="script.php"> strpos($str_lower, $end) would return the first " in the method-attribute. So I made some modifications and it seems to work fine. function ExtractString($str, $start, $end) { $str_low = strtolower($str); $pos_start = strpos($str_low, $start); $pos_end = strpos($str_low, $end, ($pos_start + strlen($start))); if ( ($pos_start !== false) && ($pos_end !== false) ) { $pos1 = $pos_start + strlen($start); $pos2 = $pos_end - $pos1; return substr($str, $pos1, $pos2); } } ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50931 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50931&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50931&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50931&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50931&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50931&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50931&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86397) next »