Posted by Nel on 06/17/05 23:12
I am trying to write a content management section for a web site.
I have managed so far to use htmlarea to give users a basic, but user
friendly interface by which to edit the page content.
The user can add emails by symply typing john@example.com - IE automatically
converts this to a hyperlink. The trouble is sometimes the users use plain
text. I have been using the following line to convert plain text to a
hyperlink:
$pagetext=ereg_replace('[A-Za-z0-9_]([-._]?[A-Za-z0-9])*@[A-Za-z0-9]([-.]?[A-Za-z0-9])*\.[A-Za-z]+',
'<a href="mailto:\\0?subject=Email%20from%20web%20site">\\0</a> ',
$pagetext);
This works well - BUT it completely screws up any existing hyperlinks. Is
there a way to convert the plain text email address in to a hyperlink only
if it is NOT part of a hyperlink.
Basically I need some way of checking
* If it's plain text > convert to a hyperlink
* If it's already an email hyperlink leave it alone.
I have tried looking up and testing everything I can think of - but am
finally asking around before I go mad.
Thanks, Nel
[Back to original message]
|