note 106835 modified in function.sqlite-escape-string by danbrown

From: Date: Sun, 11 Dec 2011 19:10:39 +0000
Subject: note 106835 modified in function.sqlite-escape-string by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185026@lists.php.net to get a copy of this message
sqlite_escape_string() does not catch all HTML characters that may conflict with a browser display. Notice the difference with the custom routine below <?php # php lib command $str = "Advoid! /slashes\, 'single' and these <too>"; $str = sqlite_escape_string($str); echo "<br>$str<br>"; # custom function $str = "Advoid! /slashes\, 'single' and these <too>"; $str = clean($str); echo "<br>$str<br>"; function clean($str) { $search = array('&' , '"' , "'" , '<' , '>' ); $replace = array('&amp;', '&quot;', '&#39;', '&lt;', '&gt;' ); $str = str_replace($search, $replace, $str); return $str; } ?> Output: Advoid! /slashes\, "single" and these Advoid! /slashes\, 'single' and these <too> --was-- sqlite_escape_string() does not catch all HTML characters that may conflict with a browser display. Notice the difference with the custom routine below # php lib command $str = "Advoid! /slashes\, 'single' and these <too>"; $str = sqlite_escape_string($str); echo "<br>$str<br>"; # custom function $str = "Advoid! /slashes\, 'single' and these <too>"; $str = clean($str); echo "<br>$str<br>"; function clean($str) { $search = array('&' , '"' , "'" , '<' , '>' ); $replace = array('&amp;', '&quot;', '&#39;', '&lt;', '&gt;' ); $str = str_replace($search, $replace, $str); return $str; } Output: Advoid! /slashes\, "single" and these Advoid! /slashes\, 'single' and these <too> http://php.net/manual/en/function.sqlite-escape-string.php

« previous php.notes (#185026) next »