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 < and > > > I have tried so many ways, but none work. here is an example of my > faliure. > > $body = > preg_replace("/(href=\/?)(\w+)(>\/?)/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 '<' and '>'? - if so, your regex can't find any >. 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="[^"]+")(>)/', '<\\2 target="_blank">', $body); var_export($body); ciao SVEN -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php