regex replace href-content
| From: | Christoph Gassmann | Date: | Sun, 24 Aug 2003 09:40:31 +0000 |
| Subject: | regex replace href-content | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-160570@lists.php.net to get a copy of this message | ||
Dear List,
I´m writing a little framework with special features for my application. The
content of my Website is in HTML-Pages from other users working with
HTML-Editors.
I parse the content in their <body> in my framework.
now I have to replace the content of their links from <a
href="test.html">test</a> to <a
href="index.php?page=test.html">test</a>. It
works fine with the following replacement.
$body2 = preg_replace('/href="(.*?)"/i',
'href="index.php?page=$1"', $body);
But if the content of their href´s is an external link (http:// at
beginning) or a javascript-link (javascript: at beginning) I don´t want to
do that.
With (?<!http:\/\/) before a word I can say, if there is an http:// in front
of, don´t replace. But it works only if I know the content of the link...
like this.
$body1 = preg_replace('/href="(?<!http:\/\/)www.test.com"/i',
'href="index.php?page=internal"', $body);
I can´t figure out how to combine the two replacements to work...
do you have any sugesstion? thanks for your help.
christoph