note 60456 added to function.strcasecmp
| From: | nicolodotborghiatemaildotit at osu1 dot php dot net | Date: | Sat, 07 Jan 2006 18:19:10 +0000 |
| Subject: | note 60456 added to function.strcasecmp | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101362@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.strcasecmp.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60456
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60456&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60456&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60456&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60456&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60456&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60456&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60456&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60456&report=yes
Search -- http://master.php.net/manage/user-notes.php