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 [email protected] into // <a href="mailto:[email protected]"> // [email protected]</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>';?> Link to comment https://forums.phpfreaks.com/topic/91341-function-not-working/ 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. Link to comment https://forums.phpfreaks.com/topic/91341-function-not-working/#findComment-468090 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); Link to comment https://forums.phpfreaks.com/topic/91341-function-not-working/#findComment-468091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.