Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,690 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,320 people online right now. Registration is fast and FREE... Join Now!




finding a link

 
Reply to this topicStart new topic

finding a link

JBrace1990
post 8 Jun, 2008 - 09:00 AM
Post #1


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 474



Thanked 21 times

Dream Kudos: 350
My Contributions


in my PM system, people can input data.... IF it contains a link, i want it to make it a hyperlink with my own onclick element.... I just need to find out HOW to find the url though...

I've gone through some things, but i can't really find anything about it.... I tried searching google, but to no avail...

the only thing I can think of is using eregi(), but that seems a little extreme to me.... anyone have a simple/good way to find a url? I can figure out the replacement myself...
User is offlineProfile CardPM

Go to the top of the page

skyhawk133
post 8 Jun, 2008 - 09:02 AM
Post #2


Head DIC Head

Group Icon
Joined: 17 Mar, 2001
Posts: 14,846



Thanked 45 times

Dream Kudos: 1650

Expert In: Web Development

My Contributions


Check out these regular expressions for URLs: http://regexlib.com/Search.aspx?k=url
User is offlineProfile CardPM

Go to the top of the page

silverblaze
post 8 Jun, 2008 - 12:24 PM
Post #3


D.I.C Head

**
Joined: 18 Jan, 2008
Posts: 51



Thanked 3 times
My Contributions


yeah regular expression is the best way to do it, i kne it seems like its tough bt its really easy. check out for a regular expression tutorial in the tutorial section. it can help u out really well.
for a begining try this stmt.

CODE

$myurl = 'http://www.yoursite.com/goto=';
$replacedmessage = preg_replace('|(http:\/\/(.*)+)|Ui',$myurl.'$1',$message);


what the above code will do is tht it will check for 'http://' and it will replace the entire string that starts with 'http://' to 'http://www.yoursite.com/goto=http://[rest of the link]' .

or u can use this

CODE

$replace = preg_replace('/(\<a.*href=[\"|\'])(.*)([\"|\']\>)/Ui','$1'.$myurl.'$2'.'$3',$text);

this will replace all the links inside the <a> tag.

hope it helps u out.

takecare.

This post has been edited by silverblaze: 8 Jun, 2008 - 12:41 PM
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 8 Jun, 2008 - 01:59 PM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 474



Thanked 21 times

Dream Kudos: 350
My Contributions


thanks guys, i'm going to take that.... there's this outbound Referrer script I have, with the help of someone from Javascript, and I want to be able to add the onclick event to check the URL....

i'll add it later and let you know how it works out =)
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 8 Jun, 2008 - 02:23 PM
Post #5


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600

Expert In: PHP, Web Security

My Contributions


I know its not in scope with this question, but just a small note on using regular expressions for html.

If you ever try to use regex to only allow certain html tags, make sure, make sure, make sure that you use recursion. Without it, an attacker can nest elements to break checks. The best way to only allow certain elements of html, is to have your own code system, like bbcode.

/offtopic
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:41AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month