Hi,
I have a rather annoying eregi_replace which I can't get to work.
I have a string, $page which contains a webpage. In the page links are
denoted like so:
###LINK###Link Name###URL or Section###ELINK###

There are a number of these in $page.

I need to use eregi_replace() to replace the above string with a proper
link:
<a href="URL or Section">Link Name</a>

Not too bad, right?
However, If need to do some manipulation on the "URL or Section" bit.
If it is a URL (begining with "http://";, "ftp://";, etc) then it just needs
to be put there, ie:
###LINK###PHP###http://www.php.net/###ELINK### = <a
href="http://www.php.net";>PHP</a>

But if it is a section on the site like this:
###LINK###Hello###Main.Section 1.Section 2.Hello World###ELINK###
It need to be replaced with this:
<a href="/main.section_1.section_2.hello_world.php">Hello</a>

Here is the rather long (an not working) eregi_replace call I have:

 $page = eregi_replace("###LINK##(.*)####(.*)###ELINK###", "<a
href=\".(eregi("^http://";, \\2) ? trim(\\2) : (strtolower(str_replace("\\",
"_", eregi_replace("(/|
|:|\*|\?|<|>|\|)","_",trim(\\2)))).".php")).">\\1</a>", $page);

1. I dont think the regular express is really right
2. I'm getting the message "Warning: Unexpected character in input: '\'
(ASCII=92) state=1 in c:\users\david\help\www\generate.php on line 24"
serval times, which is the above line.

Any ideas on how to make this work would be great! Thanks!

Regards,
David



-- 
PHP General Mailing List (http://www.php.net/)
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