Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-26-2010, 10:09 PM   PM User | #1
quadrant6
Regular Coder

 
quadrant6's Avatar
 
Join Date: Aug 2002
Location: New Zealand
Posts: 151
Thanks: 0
Thanked 0 Times in 0 Posts
quadrant6 is an unknown quantity at this point
Regular Expression Help

I'm trying to detect normal urls to other websites or pages and urls that point to files on the client site

I have this for urls which point to files, and it seems to work.

Code:
$parsed_txt = ereg_replace("(http://www.mysite.com/files/)([_a-zA-z0-9\-\/.]+)", "<a href=\"/files/\\2\" target=\"blank\" google tracking stuff...>\\0</a>", $parsed_txt);
But then after that I also want to pickup and replace urls which point to pages or websites (these links don't need google tracking stuff). I have the code below but what happens is that it also parsed the above already-parsed file links too!

Code:
$parsed_txt = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\" target=\"blank\">\\0</a>", $parsed_txt);
Normal links shouldn't have the /mysite.com/files/ part or '.' for that matter. Can anyone enlighten me to how I could write this second replace? I've been trying for about 40mins with no luck...
quadrant6 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:24 PM.


Advertisement
Log in to turn off these ads.