By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

eregi_replace problem

P: n/a
Hi

I'm having problems getting my head around eregi_replace. What I want to do
is allow users to enter links to their sites in a simple guest book. The
links can take either of 2 formats:-

http://www.nowhere.co.uk/apage.htm
which would display 'http://www.nowhere.co.uk/apage.htm' as the link text

or

click here which would
display 'click here' as a clickable link.

The first one I've managed to get working but I can't get my head around
the 2nd. Can anyone point be in the right direction please. I've looked and
looked at php.net but just can't make any sense of it :(
Mar 1 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
$url = 'click here';
$pattern = array('/\[\/url\]/i', '/\[url=/i', '/\]/i');
$replace = array('</a>', '<a href="', '">');

print preg_replace($pattern, $replace, $url);

//note: preg_* and not eregi_* used
Mar 2 '08 #2

P: n/a
On Sun, 02 Mar 2008 09:00:31 +0100, noname wrote:
$url = 'click here';
$pattern = array('/\[\/url\]/i', '/\[url=/i', '/\]/i');
$replace = array('</a>', '<a href="', '">');

print preg_replace($pattern, $replace, $url);

//note: preg_* and not eregi_* used
Thanks, that worked a treat :)
Mar 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.