Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.