27 $sPattern =
'|^' . $charToRemove .
'+|' ;
28 return preg_replace( $sPattern,
'', $sourceString ) ;
33 $sPattern =
'|' . $charToRemove .
'+$|' ;
34 return preg_replace( $sPattern,
'', $sourceString ) ;
41 '|[\xC2-\xDF][\x80-\xBF]'.
42 '|\xE0[\xA0-\xBF][\x80-\xBF]'.
43 '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'.
44 '|\xED[\x80-\x9F][\x80-\xBF]'.
45 '|\xF0[\x90-\xBF][\x80-\xBF]{2}'.
46 '|[\xF1-\xF3][\x80-\xBF]{3}'.
47 '|\xF4[\x80-\x8F][\x80-\xBF]{2}'.
50 while (preg_match(
'/'.$regex.
'/S', $string, $matches)) {
51 if ( isset($matches[2])) {
54 $string = substr($string, strlen($matches[0]));
62 if ( defined(
'PHP_OS' ) )
71 if ( strtoupper( substr( $os, 0, 3 ) ) ===
'WIN' ||
FindBadUtf8( $value ) )
73 return ( utf8_encode( htmlspecialchars( $value ) ) ) ;
77 return ( htmlspecialchars( $value ) ) ;
90 if ( !$htmlExtensions || !is_array( $htmlExtensions ) )
94 $lcaseHtmlExtensions = array() ;
95 foreach ( $htmlExtensions as $key => $val )
97 $lcaseHtmlExtensions[$key] = strtolower( $val ) ;
99 return in_array( $ext, $lcaseHtmlExtensions ) ;
112 $fp = @fopen( $filePath,
'rb' ) ;
115 if (
$fp ===
false || !flock(
$fp, LOCK_SH ) )
120 $chunk = fread(
$fp, 1024 ) ;
121 flock(
$fp, LOCK_UN ) ;
124 $chunk = strtolower( $chunk ) ;
131 $chunk = trim( $chunk ) ;
133 if ( preg_match(
"/<!DOCTYPE\W*X?HTML/sim", $chunk ) )
138 $tags = array(
'<body',
'<head',
'<html',
'<img',
'<pre',
'<script',
'<table',
'<title' ) ;
140 foreach( $tags as $tag )
142 if(
false !== strpos( $chunk, $tag ) )
149 if ( preg_match(
'!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk ) )
157 if ( preg_match(
'!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) )
163 if ( preg_match(
'!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) )
183 if (!@is_readable($filePath)) {
187 $imageCheckExtensions = array(
'gif',
'jpeg',
'jpg',
'png',
'swf',
'psd',
'bmp',
'iff');
190 if ( function_exists(
'version_compare' ) ) {
191 $sCurrentVersion = phpversion();
192 if ( version_compare( $sCurrentVersion,
"4.2.0" ) >= 0 ) {
193 $imageCheckExtensions[] =
"tiff";
194 $imageCheckExtensions[] =
"tif";
196 if ( version_compare( $sCurrentVersion,
"4.3.0" ) >= 0 ) {
197 $imageCheckExtensions[] =
"swc";
199 if ( version_compare( $sCurrentVersion,
"4.3.2" ) >= 0 ) {
200 $imageCheckExtensions[] =
"jpc";
201 $imageCheckExtensions[] =
"jp2";
202 $imageCheckExtensions[] =
"jpx";
203 $imageCheckExtensions[] =
"jb2";
204 $imageCheckExtensions[] =
"xbm";
205 $imageCheckExtensions[] =
"wbmp";
209 if ( !in_array(
$extension, $imageCheckExtensions ) ) {
213 if ( @getimagesize( $filePath ) ===
false ) {
ConvertToXmlAttribute($value)
RemoveFromEnd($sourceString, $charToRemove)
DetectHtml($filePath)
Detect HTML in the first KB to prevent against potential security issue with IE/Safari/Opera file typ...
IsHtmlExtension($ext, $htmlExtensions)
Check whether given extension is in html etensions list.
IsImageValid($filePath, $extension)
Check file content.
RemoveFromStart($sourceString, $charToRemove)