darkfreaks Posted February 15, 2008 Share Posted February 15, 2008 i have a function that is sposed to link non links and itdoes notwork when i call it it does not link the links??? <?php function replaceLinks($text) { // convert support@pogoda.in into // <a href="mailto:support@pogoda.in"> // support@pogoda.in</a> $text = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*', '<a href="mailto:\\0">\\0</a>',$text); // convert http://www.pogoda.in/new_york/eng/ into // <a href="http://pogoda.in/new_york/eng/"> // pogoda.in/new_york/eng/</a> $text = ereg_replace('[a-zA-Z]+://(([.]?[a-zA-Z0-9_/-])*)', '<a href="\\0">\\1</a>',$text); // convert www.pogoda.in/new_york/eng/ into // <a href="http://www.pogoda.in/new_york/eng/"> // www.pogoda.in/new_york/eng/</a> $text = ereg_replace('(^| )(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)', ' <a href="http://\\2">\\2</a>',$text); return $text;}?> heres how i call it: <?php echo'<textarea name="intro" id="intro" cols="60" rows="6">'.replaceLinks($intro).'</textarea>';?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 15, 2008 Share Posted February 15, 2008 Regex Section maybe? i am not very good with regex, but I am still trying to do this right now. give me a second. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 15, 2008 Share Posted February 15, 2008 //URL: Different URL parts //Protocol, domain name, page and CGI parameters are captured into backreferenes 1 through 4 '\b((?#protocol)https?|ftp)://((?#domain)[-A-Z0-9.]+)((?#file)/[-A-Z0-9+&@#/%=~_|!:,.;]*)?((?#parameters)\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?' //URL: Different URL parts //Protocol, domain name, page and CGI parameters are captured into named capturing groups. //Works as it is with .NET, and after conversion by RegexBuddy on the Use page with Python, PHP/preg and PCRE. '\b(?<protocol>https?|ftp)://(?<domain>[-A-Z0-9.]+)(?<file>/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(?<parameters>\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?' //URL: Find in full text //The final character class makes sure that if an URL is part of some text, punctuation such as a //comma or full stop after the URL is not interpreted as part of the URL. '\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]' //URL: Replace URLs with HTML links preg_replace('\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]', '<a href="\0">\0</a>', $text); 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.