Jump to content

Simple regex help.....


Recommended Posts

If I have an output buffer callback function as follows:

[code]
function callback($buffer) {
        global $offset;
        $patternUW = "@u.washington.edu$";
        if(ereg("<a href=\"mailto:(.*)\".*>.*</a>",$buffer)) {
            $buffer = eregi_replace("<a href=\"mailto:(.*)\".*>(.*)</a>","<a href=\"".$offset."/_inc/mail.php?email=\\1\">\\2</a>",$buffer);
            $buffer = callback($buffer);
            break;
        }
        return $buffer;
    }
[/code]

and I want to do the following:[ol type=\'1\'][*]Determine whether @u.washington.edu is the domain its from[*]do a different eregi_replace function if it isn't vs. if it is[*]but don't want a never-ending recursive loop[/ol]
how would I do that? I tried a simple if elseif else statement but it turned out to be neverending. Any ideas??
Link to comment
https://forums.phpfreaks.com/topic/9341-simple-regex-help/
Share on other sites

Can you explain the function you have a little more? Is it unfinished? what exactly is it trying to do? what is $offset? Why do you never use the $patternUW variable after you define it?

Why do you have the break where you do? as far as i can tell, the break will never be called because the function is re-executed before it ever gets to it.

Link to comment
https://forums.phpfreaks.com/topic/9341-simple-regex-help/#findComment-34453
Share on other sites

Basically, what's happening is I created an output buffer that will check all hyperlinks and if it finds a mailto: link, it will replace it with mail.php?email=.... . That function, callback($buffer) is used in the output buffer process as follows:

[code]
<?

ob_start('callback');

function callback($buffer) {
        global $offset;
        if(ereg("<a href=\"mailto:(.*)\".*>.*</a>",$buffer)) {
            $buffer = eregi_replace("<a href=\"mailto:(.*)\".*>(.*)</a>","<a href=\"".$offset."/_inc/mail.php?email=\\1\">\\2</a>",$buffer);
            $buffer = callback($buffer);
        }
        return $buffer;
    }
?>

//SOME HTML GOES HERE

<?

ob_end_flush();

?>

[/code]

What I want to do is add an additional ereg() function in there to check if the link is directed to an @u.washington.edu e-mail address or if the mailto: link is to some e-mail address in general. I only want to make changes to the @u.washington.edu e-mail addresses due to requirements by the department I'm working for. Any suggestions?
Link to comment
https://forums.phpfreaks.com/topic/9341-simple-regex-help/#findComment-34638
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.