Log in

View Full Version : Regular expression errors



techno_race
02-24-2010, 06:58 PM
I recently wrote a script to check which of multiple regular expressions an input matches.

It doesn't work. I get the errors:

Warning: preg_match() [function.preg-match]: Unknown modifier '{' in /home/seangill/public_html/AskMingSushi.php on line 24

Warning: preg_match() [function.preg-match]: Unknown modifier '{' in /home/seangill/public_html/AskMingSushi.php on line 24

Warning: preg_match() [function.preg-match]: Unknown modifier '{' in /home/seangill/public_html/AskMingSushi.php on line 24

Warning: preg_match() [function.preg-match]: Unknown modifier '{' in /home/seangill/public_html/AskMingSushi.php on line 24

Warning: preg_match() [function.preg-match]: Unknown modifier '{' in /home/seangill/public_html/AskMingSushi.php on line 24

Warning: preg_match() [function.preg-match]: Unknown modifier '{' in /home/seangill/public_html/AskMingSushi.php on line 24

Warning: preg_match() [function.preg-match]: Empty regular expression in /home/seangill/public_html/AskMingSushi.php on line 24

The last line repeats infinitely until I stop the page loading or my browser crashes.

I normally program in JavaScript, so it's quite likely that I did something that doesn't work in PHP. Here's the script:


$inputted = $_POST['input'];
$functions = array('big','long','array','removed');
$names = array('big','long','array','removed');
$expressions = array(
"Big long regular expression removed", //WoofNet, plain and simple
'Big long regular expression removed', //Yikes! This is for translation, believe it or not.
"Big long regular expression removed", //Adopt a pet near you today!
"Big long regular expression removed", //Who wants to adopt a pet?
"Big long regular expression removed", //What's my local weather right now?
);
$matched = array(0,0,0,0,0,0);
$numcycled = 0;
while (numcycled < count($expressions)):
/*line 24*/ if (preg_match($expressions[$numcycled], $inputted) == 1) {
$matched[$numcycled] = 1;
echo 'Matched ' . $functions[$numcycled] . ' (' . $names[$numcycled] . ').<br/>';
}
$numcycled++;
endwhile;

bluewalrus
02-24-2010, 07:08 PM
while (numcycled < count($expressions)):

while (numcycled < count($expressions)) {

techno_race
02-25-2010, 06:34 PM
Um... http://us2.php.net/while
Even with the curly braces (while(...) {...}), the error persists.