我倾向于使用 如果我在性能方面使用正则表达式会有什么不同吗? p>
div> rtrim code>,
ltrim code>和
修剪 code>以去除末端,左侧或右侧的空格。 我还使用它们去除字符串末尾或字符串开头的字符。 它比正则表达式更快吗? 以下代码有什么问题吗? p>
$ string =“hello:”;
$ string = rtrim(trim($ string),“:”); // hello
code> pre>
I tend to use rtrim
, ltrim
and trim
to strip off spaces at the end, left or right. I also use them to strip off the characters at the end or the beginning of the string. Is it faster than a regular expression? Is there anything wrong with the following code?
$string = " hello: ";
$string = rtrim(trim($string), ":"); //hello
Would it make any difference if I were to use a regular expression in terms of performance?