Tim Steele wrote:
> i need to uses reg ex to change <a href="url"> to <a href="url"
> target=_blank>
>
> the < brackets have to be represented using &lt; and &gt;
>
> I have tried so many ways, but none work. here is an example of my
> faliure.
>
> $body =
> preg_replace("/(href=\/?)(\w+)(&gt;\/?)/e","'\\1'.'\\2'./'target=_blank/
> '.'\\3'", $body);
>
> Thanks

did i understand you correct? you search in real html-code (with '<' and
'>') and want to replace them later by '&lt;' and '&gt;'?

- if so, your regex can't find any &gt;. either you search for an '>' or you
use htmlspecialchars() or htmlentities() to convert these brackets before.
- also, if in your href="" stands a full url (with
<scheme>://<domain>.<tld>) your '\w' doesn't work
- what are the optonal escaped slashes for? '\/?'

hope this helps for your start:
$body = '<a href="http://www.url";>';
$body = preg_replace ('/(<)(a href="[^"]+")(>)/', '&lt;\\2
target="_blank"&gt;', $body);
var_export($body);

ciao SVEN



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to