note 50931 deleted from function.preg-match by felipe

From: Date: Mon, 10 Dec 2007 01:40:25 +0000
Subject: note 50931 deleted from function.preg-match by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133072@lists.php.net to get a copy of this message
Note Submitter: carsten at senseofview dot de ---- 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); } }

« previous php.notes (#133072) next »