<?php $html = "<p> replace > and >> and >>> </p>"; print "<b>Original text was: '" . $html . "'\n"; $html = strrev( $html ); $newhtml = preg_replace( "/>(?![^><]+?\/?<)/", ";tl&", $html ); $newhtml = strrev( $newhtml ); print "<b>New text is: '" . $newhtml . "'\n"; ?>