Eregitation
Posted: Mon Jan 05, 2004 2:22 pm
Another eregi() question for those Gurus out there.
Is it possible to do some kind of if/else pattern search using eregi_replace() ?
What I am hoping to be able to do is change part of a link depending on where it's pointing. At the moment this is working fine for external links because I can match the http part, and with email addresses I can match the mailto: part.
The problems start with internal links (ie home.php) because I have nothing to search for (no http and no mailto)... so I guess the question is can I create a 'search pattern' that will only change links which don't contain http:// mailto: or javascript: ?
A simple example of what I'm doing at the moment is this...
As a side note I need to include the "<a href=" bit otherwise it will also change <link> objects in the <head> of the page... which is not good.
As usual I would be very greatful for any help
Is it possible to do some kind of if/else pattern search using eregi_replace() ?
What I am hoping to be able to do is change part of a link depending on where it's pointing. At the moment this is working fine for external links because I can match the http part, and with email addresses I can match the mailto: part.
The problems start with internal links (ie home.php) because I have nothing to search for (no http and no mailto)... so I guess the question is can I create a 'search pattern' that will only change links which don't contain http:// mailto: or javascript: ?
A simple example of what I'm doing at the moment is this...
Code: Select all
<?php
$f[] = "<a href="http:([^"]+)"";
$t[] = "<a href="http:\\1" onfocus="this.style.color='#ff0000'">";
$f[] = "<a href="mailto:([^"]+)"";
$t[] = "<a href="mailto:\\1" onfocus="this.style.color='#00ff00'">";
$f[] = "<a href="javascript:([^"]+)"";
$t[] = "<a href="javascript:\\1" onfocus="this.style.color='#0000ff'">";
foreach($f as $key => $value)
$buffer = eregi_replace($value, $t[$key], $buffer);
?>phpAs usual I would be very greatful for any help