Re: finding an URL in a code and creating a hypertext link with this URL
| From: | (Dave Daniels) | Date: | Thu, 10 Aug 2000 15:04:49 +0000 |
| Subject: | Re: finding an URL in a code and creating a hypertext link with this URL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11147@lists.php.net to get a copy of this message | ||
This question was asked and answered a couple days ago. I'd check the
archives.
----- Original Message -----
From: "Denis Bourdon" <dbourdon@dbourdon.com>
To: <php-general@lists.php.net>
Sent: Thursday, August 10, 2000 9:36 AM
Subject: [PHP] finding an URL in a code and creating a hypertext link with
this URL
> Hello!
>
> I have a plain text which contains URLs and I'd like to display them with
a
> link:
> The following string:
> http://www.php.net
>
> would be replaced with:
> <a
> href="http://www.php.net">http://www.php.net</a>
>
> It sounds simple but actually it is pretty hard in some cases.
>
> First problem: what are the characters that are "reserved" or
> "unsafe" in an
> URL? I found the following ones:
> [:space:] ( ) < > # % { } [ ] | \ ^ :
>
> Second problem: The URL is embedded in the text; imagine the following
sentence
> in the text:
> just look at http://www.dbourdon.com. It's worth
> visiting.
>
> OK, apart the fact that it's really worth visiting :-> just after the URL
> there
> is a dot which is ponctuation and not part of the URL.
>
> Third problem: it is to be done with EREGI_REPLACE and regular
expressions, and
> most of the signs are forbidden signs in regular expressions...
>
> So here is whatr I find just before getting a headache:
>
> $text =
EREGI_REPLACE("(http://[^([:space:]\(\)<>#%:\{\}\|\\\^)]+[^([:space:]
> \(\)<>#%:\{\}\|\\\^\.)])","<a
> href=\"\\1\">\\1</a>",$text);
>
> It does work but I think the regular expressions can be improved. I have
tried
> to read the RFCs about URL syntax but I must admit that it's impossible to
> read...
>
> Can you help me and improve the regular expression? I think some of you
has
> already dealt with this and it might be useful for lots of developers.
>
> And sorry for my poor English...
>
> Den.
>
> --
> Denis Bourdon - dbourdon@dbourdon.com
> Etudiant à Telecom Grenoble ENSIMAG/ENSERG
> site personnel: www.dbourdon.com
> webmaster de l'espace étudiants de Telecom Grenoble:
> www-telecoms.imag.fr/etudiants
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>