Pick out angle brackets
Posted: Sun Aug 02, 2009 4:24 pm
Hi there!
How do I pick out angle brackets (<>) with regex? It's for preg_replace.
Thanks.
How do I pick out angle brackets (<>) with regex? It's for preg_replace.
Thanks.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
'<' an '>' are no meta characters, so there's no need to escape them:jackpf wrote:LolCode: Select all
\<
Code: Select all
$s = 'abc < def';
echo preg_replace('/</', '', $s);Ahh right, I wasn't sure. I normally escape all non-alphanumeric characters in regex just to be sure. Better safe than sorryprometheuzz wrote:'<' an '>' are no meta characters, so there's no need to escape them:
I partly agree with you: it is indeed good to be cautious, but overly escaping characters that need not be escaped will make your regex (even) more complicated to read.jackpf wrote:Ahh right, I wasn't sure. I normally escape all non-alphanumeric characters in regex just to be sure. Better safe than sorryprometheuzz wrote:'<' an '>' are no meta characters, so there's no need to escape them: