Posts Tagged ‘strings’

PHP — Func­tion to san­i­tize string

July 17th, 2009
<?php
/**
*                             CODETREE
*                        support@mycodetree.com
*                        http://mycodetree.com
*
* RETURN: STRING
*
* USAGE:
*
* echo sanitize(" This is a/\ craz<html>y test ");
*/

function sanitize($data, $hash = false) {

   $data = mysql_real_escape_string(trim(stripslashes(strip_tags($data))));

   if ($hash) {

      $data = md5($data);

   }

   return $data;

}

?>

PHP — Find a string within a string

July 14th, 2009
<?php
/**
 *                             CODETREE
 *                      support@mycodetree.com
 *                      http://mycodetree.com
 *
*/

$content = 'this is my text';
$patterns = array('html', 'body', 'script', '<script>', '</script>');
foreach ($patterns as $value) {
if (strstr($content, $value)) {
echo "Found";
}
else {
echo "Not Found";
}
?>