Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts

    HELP - Preg match error

    here is the line of the script:
    Code:
    	  elseif(!preg_match("#^(http:\/\/www\.address\.com\//dir\//dir\//)+([a-zA-Z0-9])+(\.gif/)$#i" , $v1)) {
    and here's the error I get:
    Code:
    Warning: preg_match() [function.preg-match]: Unknown modifier 'h' in bla...bla...bla... on line 258
    thanks.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by shedokan View Post
    here is the line of the script:
    Code:
    	  elseif(!preg_match("#^(http:\/\/www\.address\.com\//dir\//dir\//)+([a-zA-Z0-9])+(\.gif/)$#i" , $v1)) {
    Code:
    preg_match("#^(http:\/\/www\.address\.com\/dir\/dir\/)+([a-zA-Z0-9])+(\.gif\/)$#i", $v1)
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    when I try to put this address it returns false:
    http://www.address.com/dir/dir/image.gif

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by shedokan View Post
    when I try to put this address it returns false:
    http://www.address.com/dir/dir/image.gif
    thats because its looking for a terminating / always...
    Code:
    preg_match("#^(http:\/\/www\.address\.com\/dir\/dir\/)+([a-zA-Z0-9])+(\.gif\/)$#i", $v1)
    change to

    Code:
    preg_match("#^(http:\/\/www\.address\.com\/dir\/dir\/)+([a-zA-Z0-9])+(\.gif\/?)$#i", $v1)
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    New Coder
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    72
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Since your regex is delimited by hash/pound signs instead of slashes, you really don't need to escape your slashes like that (one would have thought you knew that, to use hash/pound signs in the first place...)
    PHP Code:
    preg_match("#^(http://www\.address\.com/dir/dir/)+([a-zA-Z0-9])+(\.gif/?)$#i"$v1
    Incidentally, why are you allowing one-or-more (+) instance of "http://www\.address\.com/dir/dir/"?
    PHP Code:
    preg_match("#^http://www\.address\.com/(dir/)+([a-zA-Z0-9]+)(\.gif)$#i"$v1
    I don't know why you allow a slash after ".gif" so I stripped that (I point this out in case you copy & paste & confuse yourself.) Actually I have a number of questions about what exactly you're trying to capture with this regex since it seems rather weirdly (badly) constructed, so perhaps you could enlighten me for further help What cases are you expecting to encounter? What parts of those cases do you want?
    Last edited by Ahri; 11-27-2007 at 04:30 PM. Reason: extra queries
    Every PHP programmer of any skill level should set error_reporting(E_ALL); at the top of their scripts or in their php.ini

  • #6
    Regular Coder
    Join Date
    Oct 2007
    Posts
    277
    Thanks
    2
    Thanked 4 Times in 4 Posts
    I found a solution:
    Code:
    elseif(!preg_match("#^http:\/\/www\.address\.com\/dir\/dir\/[a-z0-9]+\.gif$#i" , $v1)){


  •  

    Posting Permissions

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