note 66020 deleted from function.ereg by tularis
| From: | tularis@php.net | Date: | Thu, 31 May 2007 13:21:48 +0000 |
| Subject: | note 66020 deleted from function.ereg by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127059@lists.php.net to get a copy of this message | ||
Note Submitter: petfrogg at hotmail dot com
----
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.