Mr P!nk Posted August 31, 2007 Share Posted August 31, 2007 Its called Linkparse, i found in one of my folders (not sure if its been ripped from elsewhere) and i think its a script that auto changes www.somelink.com to a valid www.somelink.com link without the need to enter the markup, (but i don't know) ive tried it in a few documents, uploaded them and tried it out but nothing has happened (in regards to me "guess") <?php function convertLinks($text) { $text = preg_replace("/(\r\n|\n|\r)/", "\n", $text); $lines = explode("\n", $text); for ($x = 0, $y = count($lines); $x < $y; $x++) { $line = $lines[$x]; $words = explode(' ', $line); for ($i = 0, $j = count($words); $i < $j; $i++) { $word = $words[$i]; $punctuation = '.,\'")(<>;:'; // Links may not end in these if (substr($word, 0, 7) == 'http://' || substr($word, 0, 4) == 'www.') { $trailing = ''; // Knock off ending punctuation $last = substr($word, -1); while (strpos($punctuation, $last) !== false) { // Last character is punctuation - eliminate it $trailing .= $last; $word = substr($word, 0, -1); $last = substr($word, -1); } // Make link, add trailing punctuation back afterwards $link = $word; if (substr($link, 0, 4) == 'www.') { // This link needs an http:// $link = 'http://'.$link; } $word = '<a href="'.$link.'" target="_BLANK">'.$word.'</a>'.$trailing; } $words[$i] = $word; } $lines[$x] = implode(' ', $words); } return implode("\n", $lines); } $link = "www.somelink.com"; echo $output = convertLinks($link); ?> If this is what i "think" it is could someone please tell/explain how I'd get it to work . Or if it's something else i wouldnt mind knowing what it is/does Thank you AA Quote Link to comment https://forums.phpfreaks.com/topic/67433-could-anyone-tell-me-what-this-isdoes/ Share on other sites More sharing options...
Mr P!nk Posted August 31, 2007 Author Share Posted August 31, 2007 a wee bump Quote Link to comment https://forums.phpfreaks.com/topic/67433-could-anyone-tell-me-what-this-isdoes/#findComment-338619 Share on other sites More sharing options...
wildteen88 Posted August 31, 2007 Share Posted August 31, 2007 The function does what you assume it does. Which is convert links written as normal text into html links, eg: www.google.com into <a href="www.google.com" target="_BLANK">www.google.com</a> Quote Link to comment https://forums.phpfreaks.com/topic/67433-could-anyone-tell-me-what-this-isdoes/#findComment-338685 Share on other sites More sharing options...
Mr P!nk Posted September 7, 2007 Author Share Posted September 7, 2007 sorry for the late reply, just beena bit busy anywho's thanks wildteen88 i know how to use it now i just wasn't determining what needs to be parsed so it was just sitting there like a lemon . i've re-jigged it a llittle tidied it up a bit, but im now faced with another problem ... <?php function parse($sample){ $Ngram = array(); $text = nl2br($sample); $Ngram = explode(" ", $text); for($i=0; $i<count($Ngram); $i++){ if(strlen($Ngram[$i]) >= 9){ if(substr($Ngram[$i],0,4) == "www."){ if(substr($Ngram[$i],-1,1) == "."){ $length = strlen($Ngram[$i])- 1; $Ngram[$i] = substr($Ngram[$i],0,$length); } $Ngram[$i] = strip_tags($Ngram[$i]); $tmp = "<a href=\"http://" . $Ngram[$i] . "\" target=\"_BLANK\">" . $Ngram[$i] . "</a>"; $Ngram[$i] = $tmp; } } } for($i=0; $i<count($Ngram); $i++){ $parsed .= $Ngram[$i] . " "; } return $parsed; } ?> i would like it to parse mail:to links , but i cant fathom out what to put and where and its driving me nuts, if anyone has a suggestion please let me know? cheers AA Quote Link to comment https://forums.phpfreaks.com/topic/67433-could-anyone-tell-me-what-this-isdoes/#findComment-343682 Share on other sites More sharing options...
Mr P!nk Posted September 7, 2007 Author Share Posted September 7, 2007 bumpy bump Quote Link to comment https://forums.phpfreaks.com/topic/67433-could-anyone-tell-me-what-this-isdoes/#findComment-343799 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.