Page 1 of 1
Can Regex make my code more efficient?
Posted: Wed Aug 02, 2006 4:49 pm
by Locust
Code: Select all
$smessage = ereg_replace("\"", """, $_POST['field']);
$smessage = ereg_replace("<", "<", $smessage);
$smessage = ereg_replace(">", ">", $smessage);
$smessage = ereg_replace("'", "'", $smessage);
$smessage = ereg_replace("&", "&", $smessage);
Basically getting characters that could possibly tamper with HTML to be replaced with HTML-friendly characters. Should I go about this a different way?
Posted: Wed Aug 02, 2006 4:50 pm
by Luke
htmlentities()
Posted: Wed Aug 02, 2006 4:52 pm
by Locust
Didn't know about that one
Thanks
Posted: Wed Aug 02, 2006 4:54 pm
by Locust
I also had another line I didn't add
Code: Select all
$smessage = ereg_replace(13, "<br>", $smessage);
To replace carriage returns. htmlentities() does not compensate for this. Should I use the code I wrote?
Posted: Wed Aug 02, 2006 4:57 pm
by feyd
ereg is slow and soon to be deprecated.
htmlentities() doesn't care about carriage returns, they aren't entities.
nl2br()
Posted: Wed Aug 02, 2006 5:02 pm
by Locust
Perfect
