|
Posted by Jim Michaels on 02/28/06 02:30
"Arjen" <dont@mail.me> wrote in message
news:440071d6$0$10433$2c885b36@newsreader5.eweka.nl...
>I currently convert hyperlinks on my site with this piece of code
>
> $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a
> href=\"\\0\">\\0</a>", $text)
>
>
> Is there anyway to shorten the second part of the link linke this
yes. you can remove the www.
actually, you can try two different things. try these variations on your
theme. () allows you to group things and refer back to the grouping as \1 \2
\3 ...
C:\>php
<?php
$text = "http://www.mysite.com/this/that";
$text = ereg_replace('[[:alpha:]]+://([^<>[:space:]"\']+[[:alnum:]/_.-]+)',
"<a href=\"\\0\">\\1</a>", $text);
print $text;
?>
^Z
<a href="http://www.mysite.com/this/that">www.mysite.com/this/that</a>
C:\>php
<?php
$text = "http://www.mysite.com/this/that";
$text =
ereg_replace('[[:alpha:]]+://[^<>[:space:]"\'/]+(/[[:alnum:]/_.-]*)?', "<a
href=\"\\0\">\\1</a>", $text);
print $text;
?>
^Z
<a href="http://www.mysite.com/this/that">/this/that</a>
C:\>
> <a href
> ="http://www.mysite.com/longtext_and_more_stuff>http://www.mysite.com/lon
> ...</a>
>
> Im just no sure how to do this ... ive tried substr and all that but the
> problem is I dont know wich url im working at cause this piece of code
> just changes all the urls in the text
>
> Arjen
Navigation:
[Reply to this message]
|