SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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 ?

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

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Well let us put on our magics hats first otherwise I psychic powers are nerfed :O
    Need more data like what is request_var, what data is failing....etc.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    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...

  4. #4
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [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 ?

    PHP Code:
              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)

  5. #5
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    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...
    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.

  6. #6
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Ok, with that clarification you would probably need to use a regex...

    My advice: google is your friend:
    http://www.regexguru.com/2008/11/det...block-of-text/
    http://blogs.lse.ac.uk/clt/2008/04/2...match-any-url/

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

  7. #7
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, but some methods are more bullet-proof than others! ;-)

  8. #8
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Your problem is the '.' in the '.com'. The dot means 'any character'. Escape it with a backslash and it should be fine:
    PHP Code:
    if (preg_match('/(http|www|\.com|\.es|\.co\.uk|\.info|\.org)/i'request_var('message'''true))) 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  9. #9
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,416
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant Jake - problem solved, many thanks for the useful help.


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
  •