Connecting Tech Pros Worldwide Forums | Help | Site Map

"Ereg_replace" regular expression woes

Rob Pridham
Guest
 
Posts: n/a
#1: Jul 17 '05
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|rtsp)://[^[: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
Guest
 
Posts: n/a
#2: Jul 17 '05

re: "Ereg_replace" regular expression woes


Rob Pridham wrote:[color=blue]
> $string = eregi_replace(" ((http|https|rtsp)://[^[: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 =--
Closed Thread