Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2003
    Location
    AZ
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    calling functions in ereg()

    this will match "[name=coffeedemon]" and i want to attempt it to call a function "displayName()" with coffeedemon as the argument. Can i do this?

    ereg_replace("(\[name=)([a-zA-Z0-9]{3,20})(\])",displayName("\\2"),$str);

    displayName() is something along the lines of

    function displayName($name)
    {
    // name
    $newName = ereg_replace('('. $name .')', "<a href=\"http://\\1.domain.com/\">\\1</a>", $name);



    $result = $newName;

    return $result;
    }
    PHP | FreeBSD | MySQL |
    Check documentation... check documentation again and actually read it..do it... doesn't work ask.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think you're reaching beyond the capabilities of ereg_replace() in this context. The ereg_* functions are very basic regex functions compared to the much more powerful preg_* functions.

    In your case, you can accomplish that by using either preg_replace() and the "e" modifier in your regex, or by calling preg_replace_callback().

    For the first possibility, got the documentation page (http://us2.php.net/manual/en/function.preg-replace.php) and look at example 4 to get an idea how the "e" modifier should be used.

    The second possibility is more straightforward to use IMO, because it doesn't rely on those cryptic modifiers. Take your pick.
    De gustibus non est disputandum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •