note 52259 added to ref.strings
| From: | phpatmoechofedotcom at osu1 dot php dot net | Date: | Tue, 26 Apr 2005 13:34:26 +0000 |
| Subject: | note 52259 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88563@lists.php.net to get a copy of this message | ||
<?php
/*
* str_match
*
* return a string with only cacacteres defined in a expression return false if the expression is
not valid
*
* @param $str string the string
* @param $match the expression based on the class definition off a PCRE regular expression.
* the '[', ']', '\' and '^' at class start need to be
escaped.
* like : -a-z0-9_@.
*/
function str_match( $str, $match )
{
$return = '';
if( eregi( '(.*)', $match, $class ) )
{
$match = '['.$regs[1].']';
for( $i=0; $i<strlen($str); $i++ )
if( ereg( '['.$class[1].']', $str[$i] ) )
$return .= $str{$i};
return $return;
}
else return false;
}
/*
* example
* accept only alphanum caracteres from the GET/POST parameters 'a'
*/
if( ! empty($_REQUEST['a']) )
$_REQUEST['a'] = str_match( $_REQUEST['a'], 'a-zA-Z0-9' );
else
$_REQUEST['a'] = 'default';
?>
----
Manual Page -- http://www.php.net/manual/en/ref.strings.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52259
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52259&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52259&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52259&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52259&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52259&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52259&report=yes
Search -- http://master.php.net/manage/user-notes.php