RE: [PHP] preg_replace help
| From: | Boaz Yahav | Date: | Sat, 12 Jan 2002 20:43:28 +0000 |
| Subject: | RE: [PHP] preg_replace help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-80310@lists.php.net to get a copy of this message | ||
Here are some scripts to help you :
http://www.weberdev.com/index.php3?GoTo=get_example.php3?count=1235
http://www.weberdev.com/index.php3?GoTo=get_example.php3?count=1234
http://www.weberdev.com/index.php3?GoTo=get_example.php3?count=1401
http://www.weberdev.com/index.php3?GoTo=get_example.php3?count=1403
Sincerely
berber
Visit http://www.weberdev.com Today!!!
To see where PHP might take you tomorrow.
-----Original Message-----
From: Gaylen Fraley [mailto:gfraley5@earthlink.net]
Sent: Saturday, January 12, 2002 5:20 AM
To: php-general@lists.php.net
Subject: [PHP] preg_replace help
I have need to be able to replace text within a string to turn it into a
link. In other words, I might have a phrase lik:
"blah, blah, blah, please visit my site at www.mysite.com. blah,
blah,blah".
I need to have the string converted to "blah, blah, blah, please visit
my
site at http://www.mysite.com. blah, blah,blah". The link
might have
more
than 3 sections and won't necessarily end in .com (.net,.com.nl, etc.).
Here is what I have been testing (then I get stuck):
$myLink = "Please visit my web site at www.mysite.com. You will be glad
you
did!";
$repLink = preg_replace("/(www.)/i","<a href=http://\\1",$myLink);
which yields
Please visit my web site at <a href=http://www.mysite.com.
You will be
glad
you did!
What I would need is
Please visit my web site at <a
href=http://www.mysite.com>www.mysite.com</a>. You will
be glad you did!
To be truthful, pattern matching is giving me migraines! Programming
has
always been natural to me (32 years of it), but this challenge (eregi,
preg_match,etc.) is making me crazy! Can someone recommend a good
tutorial
or book on this subject?
Thanks!
--
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