|
Posted by Markus L. on 10/14/05 22:37
Am Fri, 14 Oct 2005 12:23:24 -0700 schrieb specjal:
> 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>";
> }
>
>
> ?>
$tresc = preg_replace('/(http)(s?)(://)([^ ]+)/', '<a
href="$1$2$3$4">$1$2$3$4</a>', $tresc);
--
-------------------------------------------------------
Try this: SCA the Smart Class Archive for PHP
http://www.project-sca.org
-------------------------------------------------------
Navigation:
[Reply to this message]
|