Jump to content


Photo

Simple regex help.....


  • Please log in to reply
3 replies to this topic

#1 milesperhour1086

milesperhour1086
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 May 2006 - 09:10 PM

If I have an output buffer callback function as follows:

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;
    }

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??
Micah[br] --PHP Newbie

#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 08 May 2006 - 10:33 PM

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.


If you're not part of the solution, you're part of the precipitate

#3 milesperhour1086

milesperhour1086
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 09 May 2006 - 03:27 PM

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:

<?

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();

?>


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?
Micah[br] --PHP Newbie

#4 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 10 May 2006 - 02:09 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users