[thelist] regex help needed

kris burford [midtempo] kris at midtempo.net
Tue May 21 06:02:01 CDT 2002


hi all,

delving into regex for the first time and i'm having issues (surprise,
surprise!)

i've got a cms system where the client can type in their product codes into
the body text. i'm attempting to identify these codes and create urls to
the respective products passing the code in the url. the codes are
identified by either one or two capital letters followed by 2-3 digits.

so far i've got

$match = array();
$string = "one two three UR12 four five six";
if (ereg ("[A-Z]{1,2}[0-9]{2,3}", $string, $match)) {
	for ($i=0; $i < count($match); $i++) {
		$new_match = '<a href="page.html?ref=' . $match[$i] . '">' . $match[$i] .
'</a>';
		$string = ereg_replace($match[$i], $new_match, $string);
	}
}
echo $string;

but i'm getting a count($match) of 10 and no joy on the ereg_replace. can
anyone point me in the right direction? (if there's a better way to do
this, i'd also be most grateful for any advice...)

tia

kris



More information about the thelist mailing list