chris chris - 1 year ago 65
PHP Question

Image URL preg_match failing, can't figure out why

So I tested this pattern at regex101, and it works, but when I load it up into PHP I keep getting false, can someone please explain to me why?

preg_match('/^(https?|ftp):\/\/.*(jpeg|png|gif|bmp|jpg)/gi', $_POST['damageImage'])

would be equal to
for example sake.

I have also tried this with
still recieving a false. All I want to do is a simple if-else statement and I can't get past this simple thing. Its got me stumped, what is the overall pitfall I am tripping over here?

Answer Source

Remove g modifier

$url = '';
preg_match('/^(https?|ftp):\/\/.*(jpeg|png|gif|bmp|jpg)/i', $url, $match);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download