codeboy89 Posted February 7, 2010 Share Posted February 7, 2010 Alright, I found the following function online. function HyperlinkText($text) { return ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\">\</a>", $text); } Can anyone explain to me how I would use this function to turn a url into a clickable link. I want to use it on a input field named "bull". Here is my code currently that takes data and submits it to an XML file to be viewed. $file_name = "bb.xml"; $file_act = fopen($file_name, "r+"); $lock = flock($file_act, LOCK_EX); $file_read = fread($file_act, filesize($file_name)); $date = date ("j M Y"); $post = "<bb>\n<p>$name $date<br />$bull</p>\n</bb>\n"; $post = stripslashes($post); fwrite($file_act, "$post"); fclose($file_act); I am not sure how to incorporate this function. I would really appreciate any help. Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 7, 2010 Share Posted February 7, 2010 Well it seems fairly obvious that you will want to try and call your HyperlinkText() function. How about: $post = HyperlinkText(stripslashes($post)); Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 8, 2010 Share Posted February 8, 2010 When you call it you wont get anything. replace it with: ereg_replace("(^| |.)(www([.]?[a-zA-Z0-9_/-])*)", "<a href=\"http://\\2\">\\2</a>", $text) Your input should be www.domain.com or domain.com HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
codeboy89 Posted February 8, 2010 Author Share Posted February 8, 2010 I added the function, and called it the way gizmola has shown above. It does not work. Nothing updates at all. Quote Link to comment Share on other sites More sharing options...
codeboy89 Posted February 8, 2010 Author Share Posted February 8, 2010 I forgot to mention I want this to find and make any urls into links, that is what the original ereg_replace is supposed to do. It is not a url only input field. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.