Forum Moderators: coopster

Message Too Old, No Replies

Using "regular expressions"

Isolating URL's in a long string

         

zoltek

8:52 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



Hi,

Let's say I have a long string, which could contain a URL.

The URL can be in one of three formats at this points (ignore the spaces before the tags):

[ url]http://www.link.com[ /url]
[ url=http://www.link.com]Link Title[ /url]
[link.com...]

I'm trying to use preg_match_all() to isolate all instances of a link and store it in an array.

The problem is, I'm not sure what sort of 'regexs' I can use to isolate those links.

Any help would be greatly appreciated.

mcavill

9:10 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



I'm no Regex or PHP expert - but something like:

"http://((.¦\n)*?)(\.com¦\.net¦\.co\.uk¦\.org¦\.info¦\.biz)" may work (you'll need to add more domainname extentions)...and I'm sure there's better ways of doing it....

[edited by: ergophobe at 12:24 am (utc) on Feb. 14, 2005]

zoltek

9:46 pm on Feb 13, 2005 (gmt 0)

10+ Year Member



Great. Thanks! I'll see if that code works.

[edited by: ergophobe at 12:25 am (utc) on Feb. 14, 2005]

ergophobe

12:26 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you Google on

regular expressions
regular expressions tutorial
regular expressions reference

You'll get a week's worht of good reading. Enjoy!

jamie

7:15 am on Feb 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



zoltek,

why not download one of the popular php forums and see what they do as well?

i have tried this and it is not so easy to catch all

zoltek

9:23 am on Feb 14, 2005 (gmt 0)

10+ Year Member



I finally got it to work, at least in terms of catching the formats URL's take in forum posts.

"/http:\/\/[^\s\[\]]*/"