473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

eregi_replace problem

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
2 1319
$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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: fartsniff | last post by:
Hello all. I am starting to work on a URL "cleaner" of sorts. The code below is only checking for a few simple entries on the URL, but for some reason it is not replacing them with "" when...
4
by: David | last post by:
Hi, I've had a search through google but couldn't really find the answer I was looking for.I'm new to PHP, so please take it <relatively> easy. I've created a script which runs some SNMP...
1
by: Florian Leeber | last post by:
Hi! I try to: function do_bug_link($in) { return eregi_replace("\!(+)","<a href='bug.php?op=show&bugid=\\1'>Bug \\1</a>",$in); }
117
by: Peter Olcott | last post by:
www.halting-problem.com
2
by: saiena | last post by:
Is there a way in my regular expression syntax to cause alternating occurences of the search string to be replaced? Here's my code: $item = eregi_replace($search_string, $replace_string,...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
9
by: Bob | last post by:
Hi, Maybe this problem has already been mentionned, but I am new to this group, so here we go. $string = "This is for ABC only" $new = (eregi_replace('ABC','<b>ABC</b>',$string)); print...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.