You are here: string http:// conwert to <a href=''>host</a> « PHP Programming Language « IT news, forums, messages
string http:// conwert to <a href=''>host</a>

Posted by specjal on 10/14/05 22:23

hi

in form TEXTAREA i have text like:

bla bla http://www.google.com/bla/bla/bla text text text text


now how to make from this text like:

bla bla ['http://www.google.com'] text text text text


['']-> url to http://www.google.com/bla/bla/bla


I wrote this script:
Were error is?


ps. sorry , my english is not good.:)
<?


function string_url($text) {

$arr=explode("\n", $text);
$j=0;


foreach( $arr as $val)
{

if( strlen($val) > 1 )
{


$arr2=explode(" ", $val);
$i=0;
foreach( $arr2 as $val2)
{

$findme = 'http';
$pos = strpos($val2, $findme);
if ($pos === false)
{

$arr2[$i] = $val2;
}

else {

$val2=parse_url($val2);
$host=$val2['host'];
$path=$val2['path'];
$scheme=$val2['scheme'];
$tekst="<a HREF=\"$scheme://";
$tekst.=$host;
$tekst.=$path;
$tekst.=">$host</a>";
$arr2[$i]=$tekst;
}

$i++;
}//koniec 2 forech (slowa)
$slowa=implode(" ", $arr2);
$arr[$j] = $slowa;

}


else
{
$arr[$j] = $val;
}

$j++;
}//koniec 1 forech
$text_nowy= implode("\n", $arr);
return $text_nowy;
}




if ( $tresc) {

echo string_url($tresc);


} else {


print "<FORM METHOD=POST > </B><B>title:</B><BR>";
print "<TEXTAREA NAME=tresc ROWS=30 COLS=60
>$tresc</TEXTAREA><BR>";
print "<br><INPUT TYPE=\"submit\" VALUE=\"add!\"><br><br>";
print "</FORM>";
}


?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация