note 60456 deleted from function.strcasecmp by nlopess
| From: | nlopess@php.net | Date: | Sat, 07 Jan 2006 20:02:33 +0000 |
| Subject: | note 60456 deleted from function.strcasecmp by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101364@lists.php.net to get a copy of this message | ||
Note Submitter: nicolo dot borghi at email dot it
----
I don't know if something similar already exsists in php, but i wrote a function to find out if
a string is contained into another longer. For example you can use this function in a directory
listing if you want to disallow the access to subdirectories.
<?php
function contains($str, $pattern)
{
$len = strlen( $str );
$len_pat = strlen( $pattern );
for( $i = 0; $i < $len; $i ++ )
{
$check = substr( $str, $i, $len_pat );
if ( strcasecmp($check, $pattern) == 0 )
{
return true;
}
}
return false;
}
?>
$str is the string you're watching in
$pattern is the string you're looking for