First of all, thanks to everyone who replied!  I have several good
suggestions.  Here is one that seems to work pretty well, to cover a
multitude of situations:

 $msg =
href=\"\\1://\\2\\3\" target=\"_blank\">\\1://\\2\\3</a>", $msg);

The only problem is that if a correctly formatted link is already in the
text, then this routine tries to add an additional href and it gets all
messed up.  Is there any way that I can use this algorithm and logically
tell it not to do the replace if the anchor tags are already in place?  I
can't just search for an anchor <a> tag because there can be several in the


$myLink = "<a href=\"\"; target=\"_n\">Testing</a>";
echo makeLink($myLink);

Creates $msg =

<a href="<a href="";
target="_blank"></a>" target="_n">Testing</a>

Any suggestions?

"Gaylen Fraley" <[EMAIL PROTECTED]> wrote in message
> 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  blah,
> blah,blah".
> I need to have the string converted to "blah, blah, blah, please visit my
> site at  blah, blah,blah".  The link might have
> than 3 sections and won't necessarily end in .com (.net,, etc.).
> Here is what I have been testing (then I get stuck):
> $myLink = "Please visit my web site at You will be glad
> did!";
> $repLink = preg_replace("/(www.)/i","<a href=http://\\1",$myLink);
> which yields
> Please visit my web site at <a href= You will be
> you did!
> What I would need is
> Please visit my web site at <a
> href=></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
> or book on this subject?
> Thanks!

PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to