I have a somewhat complex search and replace algorithm that uses many different string functions. Rather than peppering my code with things like this:
$mb = true; // use mb functions or not
$len = $mb? mb_strlen($s) : strlen($s);
I'm thinking of doing this, just once:
$_strpos = $mb? 'mb_strpos' : 'strpos';
$_substr = $mb? 'mb_substr' : 'substr';
$_strlen = $mb? 'mb_strlen' : 'strlen';
Then I can use code like this:
$len = $_strlen($s);
It works. The code is much shorter and clearer, and I think it should be faster. Is there any reason not to do this?
mb_functions always?mb_functions always because some users won't have it installed. In some situations it could be a very large number of string manipulations and using the_mbfunctions roughly doubles the time to get a response.