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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts

    Extract domains from string

    Hello everybody,

    I have a forum script, and I would like get all the domains (array?) from a string and compare it against the current domain to prevent users from linking "off-site".

    Now, this would mess with images offsite, so I was wondering if anybody would help me accomplish this with REGEX to comply with the bbcode

    Please and thank you,

    nobackseat

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Do you have any code already? if you have all the URL's already (by the forum code giving you them) all you need to do is use parse_url() and then get the domain from that
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #3
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Hello,

    Not really, when I stated Forum Script, I was referring to my purpose for needing this.

    This is what I came up with I think, but it wouldn't work for the BBCode...

    PHP Code:
    $url preg_match('/http:\/\/\s+/'$message$results); 
    The only other time I have seen this asked on the Web (after hours of searching Google & popular sites) is here
    http://bytes.com/topic/php/answers/5...n-string-regex
    and it still wasn't solved.

    Thanks for your time,

    nobackseat
    Last edited by nobackseat88; 01-18-2010 at 05:32 PM.

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    what forum software are you using? There will probably already be a mod for this
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Jay,

    I made my own script, but the problem is extracting domain names from BBCode.

    nobackseat

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP Code:
    '%https?://([^/]+)%' 
    Should work for you. It will return the domain in $results[1]
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    nobackseat88 (01-18-2010)

  • #7
    Regular Coder
    Join Date
    Dec 2007
    Posts
    145
    Thanks
    5
    Thanked 5 Times in 5 Posts
    Jay,

    Thanks so much for your help. Would anybody mind implementing the BBCode

    PHP Code:
    [url=][/url
    into this? I suck at REGEX.

    nobackseat

  • #8
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    Try implementing this class
    http://www.christian-seiler.de/proje.../index_en.html
    If that one doesn't work, try more "php bbcode class" googles and see what it brings up. Should find one that will do it
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)


  •  

    Posting Permissions

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