Jump to content

Archived

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

milesperhour1086

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??

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
this may be an archaic way of doing things, but i would suggest simply matching once with a pattern that picks up ONLY U of Washington addies, and once more recognizing the general pattern.

Share this post


Link to post
Share on other sites

×

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.