note 12835 deleted from function.ereg by jimw

From: Date: Fri, 02 Nov 2001 01:27:30 +0000
Subject: note 12835 deleted from function.ereg by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20143@lists.php.net to get a copy of this message
In order to find multiple matchs in a single string I created this function. <? function ereg_all($str,$regex){ do{ if(!ereg($regex,$str,$temp)) continue; $str=str_replace($temp[0],'',$str); $results[]=$temp; }while(ereg($regex,$str,$temp)); return $results; } $str = '"Captain Kirk", "Ace Ventura", "Dave Matthews"'; $regex = '"([^"]+)*"'; $found = ereg_all($str,$regex); echo "These are the matches I found: "; for($i=0;$i<count($found);$i++) echo "&lt;".$found[$i][1]."&gt;"; echo "<br>I built the following array:<pre>"; print_r($found); echo "</pre>"; ?> -- for REAL power develop using MacOS, BBEdit, and PHP. The "Holy Trinity"! -Bruno

« previous php.notes (#20143) next »