"Ereg_replace" regular expression woes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Pridham

    "Ereg_replace" regular expression woes

    Hi.

    I'm trying to use ereg_replace to turn some text based hyperlinks into WML
    code. WML is similar to HTML, except for mobile phones and very strict. That
    means that there's some characters you can't use in certain places. Here's
    my current code.

    $string = eregi_replace(" ((http|https|rt sp)://[^[:space:]]+[[:alnum:]/])","
    <a href=\"\\1\">\\ 1</a>", $string);

    That almost works well enough, but I need to add some more conditions. The
    output CANNOT contain the words:

    & q u o t ;
    & g t ;
    & l t ;

    (ignore the spaces). If it does find those things it should break off, just
    like when it finds a space. So far attempts to add this in have been
    completely fruitless. Help would be very much appreciated!

    Rob


  • Pedro Graca

    #2
    Re: &quot;Ereg_repl ace&quot; regular expression woes

    Rob Pridham wrote:[color=blue]
    > $string = eregi_replace(" ((http|https|rt sp)://[^[:space:]]+[[:alnum:]/])","
    ><a href=\"\\1\">\\ 1</a>", $string);
    >
    > That almost works well enough, but I need to add some more conditions. The
    > output CANNOT contain the words:
    >
    > & q u o t ;
    > & g t ;
    > & l t ;
    >
    > (ignore the spaces). If it does find those things it should break off, just
    > like when it finds a space. So far attempts to add this in have been
    > completely fruitless. Help would be very much appreciated![/color]

    I think your best bet is to search for the forbidden content directly
    and not within a regular expression.

    Do the eregi_replace and then test for the forbidden content, maybe with
    something like:

    <?php
    // ... including the eregi_replace()
    if (strpos($string , '&quot;') !== false) die('broken URL');
    if (preg_match('/&[gl]t;/', $string)) die('broken URL');
    // ...
    ?>
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    Working...