...

View Full Version : HELP - Preg match error



shedokan
11-27-2007, 02:30 AM
here is the line of the script:

elseif(!preg_match("#^(http:\/\/www\.address\.com\//dir\//dir\//)+([a-zA-Z0-9])+(\.gif/)$#i" , $v1)) {

and here's the error I get:

Warning: preg_match() [function.preg-match]: Unknown modifier 'h' in bla...bla...bla... on line 258



thanks.

shyam
11-27-2007, 09:45 AM
here is the line of the script:

elseif(!preg_match("#^(http:\/\/www\.address\.com\//dir\//dir\//)+([a-zA-Z0-9])+(\.gif/)$#i" , $v1)) {



preg_match("#^(http:\/\/www\.address\.com\/dir\/dir\/)+([a-zA-Z0-9])+(\.gif\/)$#i", $v1)

shedokan
11-27-2007, 03:12 PM
when I try to put this address it returns false:
http://www.address.com/dir/dir/image.gif

shyam
11-27-2007, 03:16 PM
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...


preg_match("#^(http:\/\/www\.address\.com\/dir\/dir\/)+([a-zA-Z0-9])+(\.gif\/)$#i", $v1)

change to


preg_match("#^(http:\/\/www\.address\.com\/dir\/dir\/)+([a-zA-Z0-9])+(\.gif\/?)$#i", $v1)

Ahri
11-27-2007, 04:22 PM
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...)

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/"?

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?

shedokan
11-27-2007, 06:31 PM
I found a solution:

elseif(!preg_match("#^http:\/\/www\.address\.com\/dir\/dir\/[a-z0-9]+\.gif$#i" , $v1)){



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum