Advanced Search

Results 1 to 3 of 3

Thread: Regular expression errors

  1. #1
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default Regular expression errors

    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:

    PHP Code:
    $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; 
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Code:
    while (numcycled < count($expressions)): 
    
    while (numcycled < count($expressions)) {
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default

    Um... http://us2.php.net/while
    Even with the curly braces (while(...) {...}), the error persists.
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •