regex - PHP trim/rtrim/ltrim VS Regular expression -
i tend use rtrim
, ltrim
, trim
strip off spaces @ end, left or right. use them strip off characters @ end or beginning of string. faster regular expression? there wrong following code?
$string = " hello: "; $string = rtrim(trim($string), ":"); //hello
would make difference if use regular expression in terms of performance?
regular expressions make things slower, applied such small strings, due expression analysis overhead.
assuming colon never appear on left side, eliminate rtrim()
:
$string = trim($string, ": "); // trim either space or colon on either side
Comments
Post a Comment