Forum Moderators: coopster
Anyway the general idea is that I want to be able to locate the urls in the "Tweet" string and then change them from "http://www.example.com" to
<a href="http://www.example.com">http://www.example.com</a> Also generally speaking they will be in the form "http://bit.ly/123456" where "123456" is a string of any numbers/letters. I don't want to exclusively pick these types of urls though either.
Hope that's enough information!
Thanks in advance
function getLink($string){
//keep this as the original
$constant = $string;
//remove any line breaks
$string = ereg_replace("\n", " ", $string);
//add one white space to the end in case
//there is a link as the very last thing
$string .= " ";
//get the first http:
$pos = stripos($string, "http:");
//an array of the links we need to return
$links = array();
//while we have http keep going through it
while($pos !== false){
$end = (stripos($string, " ", $pos));
$url = substr($string, $pos, ($end - $pos));
array_push($links, $url);
$string = substr($string, $end);
$pos = stripos($string, "http:");
}//while
//now we replace the string
foreach($links as $i){
$constant = str_ireplace($i, "<a href=\"{$i}\">{$i}</a>", $constant);
}//foreach
echo(($constant));
}//createLink
//now we replace the string
foreach($links as $i){
to:
}//while
$links = array_unique($links);
//now we replace the string
foreach($links as $i){
just add the array_unique line. Just an FYI.