...

View Full Version : Extract domains from string



nobackseat88
01-18-2010, 05:21 PM
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

JAY6390
01-18-2010, 05:26 PM
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

nobackseat88
01-18-2010, 05:30 PM
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...



$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/528020-how-extract-domain-string-regex
and it still wasn't solved. :(

Thanks for your time,

nobackseat

JAY6390
01-18-2010, 05:37 PM
what forum software are you using? There will probably already be a mod for this

nobackseat88
01-18-2010, 05:38 PM
Jay,

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

nobackseat

JAY6390
01-18-2010, 05:40 PM
'%https?://([^/]+)%'
Should work for you. It will return the domain in $results[1]

nobackseat88
01-18-2010, 05:43 PM
Jay,

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


into this? I suck at REGEX. :(

nobackseat

JAY6390
01-18-2010, 05:53 PM
Try implementing this class
http://www.christian-seiler.de/projekte/php/bbcode/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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum