Why would this not work please?

Have been working on some PHP code and trying to implement the below code on a forum, and has generally worked okay when a poster is just posting their post only, BUT, when they’re also quoting another users post within theirs, without apparently going against any of the coding below, it gives the error message as if someone has posted one of the below? Is it the [quote] code that appears when quoting someone elses post ?


          if (preg_match('/(http|www|.com|.es|.co.uk|.info|.org)/i', request_var('message', '', true)))

Well let us put on our magics hats first otherwise I psychic powers are nerfed :open_mouth:
Need more data like what is request_var, what data is failing…etc.

What’s that even supposed to do – not a very good check for a URL since if any one of those conditions is true, it works… That is supposed to be a test for a valid URL, right?

I’d probably be checking against parse_url instead of trying to use a regex… since that will give you the individual scheme and host values… or false if it’s malformed.

http://php.net/manual/en/function.parse-url.php

or

http://us2.php.net/manual/en/function.parse-url.php

since php.net and most of the mirrors appear to be DOWN right now… of all the ones I tried only us2 is working…

[QUOTE=Dez;5066331]Have been working on some PHP code and trying to implement the below code on a forum, and has generally worked okay when a poster is just posting their post only, BUT, when they’re also quoting another users post within theirs, without apparently going against any of the coding below, it gives the error message as if someone has posted one of the below? Is it the

code that appears when quoting someone elses post ?


          if (preg_match('/(http|www|.com|.es|.co.uk|.info|.org)/i', request_var('message', '', true)))

Put away the crystal ball, it’s not needed. With the .com in the code, it’s also picking up on the words command, competition etc - is there any way that it can just pick up on the .com - (only if it has the dot as the prefix)

Many thanks for the info - much appreciated. Just to clarify, it’s to stop people who haven’t made a certain number of posts, posting a website address, in any form, so for example, if they post just abcdef.com (without any www’s) it would still give an error message.

Ok, with that clarification you would probably need to use a regex…

My advice: google is your friend:
http://www.regexguru.com/2008/11/detecting-urls-in-a-block-of-text/

those have some VERY complete and thorough methods, but beware that no such technique is EVER bulletproof.

Yep, but some methods are more bullet-proof than others! :wink:

Your problem is the ‘.’ in the ‘.com’. The dot means ‘any character’. Escape it with a backslash and it should be fine:

if (preg_match('/(http|www|\\.com|\\.es|\\.co\\.uk|\\.info|\\.org)/i', request_var('message', '', true)))

Brilliant Jake - problem solved, many thanks for the useful help.