note 66020 added to function.ereg
| From: | petfrogg at hotmail dot com | Date: | Fri, 12 May 2006 10:06:17 +0000 |
| Subject: | note 66020 added to function.ereg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111175@lists.php.net to get a copy of this message | ||
According to the manual the usage of regexps are slower then build in functions. I was faced with
the need of a conf-file in order to confirm to the company standard and in order to fix this I
needed to parse strings and automaticly set the correct âtypeâ of every type fetched from
the conf-file as strings. Iâve red some examples of this using eregs but none worked for me.
This is my working solution:
function _setType($mValue){
$mReturnData = trim($mValue);
switch($mReturnData){
case strtolower($mReturnData)== 'true':
$mReturnData = true;
break;
case strtolower($mReturnData)== 'false':
$mReturnData = false;
break;
case strtolower($mReturnData)== 'null':
$mReturnData = null;
break;
case is_numeric($mReturnData):
if($mReturnData == (integer)$mReturnData){
$mReturnData = (integer)$mReturnData;
}else{
$mReturnData = (float)$mReturnData;
}
break;
default:
$mReturnData = $mReturnData;
}
return $mReturnData;
}
Hope it will help someone.
----
Server IP: 129.16.214.50
Probable Submitter: 212.112.184.254
----
X-Spam-Status: Yes, hits=7.4 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HEAD_ILLEGAL_CHARS autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.ereg.php
Edit -- http://master.php.net/note/edit/66020
Del: integrated -- http://master.php.net/note/delete/66020/integrated
Del: useless -- http://master.php.net/note/delete/66020/useless
Del: bad code -- http://master.php.net/note/delete/66020/bad+code
Del: spam -- http://master.php.net/note/delete/66020/spam
Del: non-english -- http://master.php.net/note/delete/66020/non-english
Del: in docs -- http://master.php.net/note/delete/66020/in+docs
Del: other reasons-- http://master.php.net/note/delete/66020
Reject -- http://master.php.net/note/reject/66020
Search -- http://master.php.net/manage/user-notes.php