Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
rtrim私は,ltrimを使用する傾向がありtrim、左または右の最後にあるスペースを取り除きます。また、文字列の末尾または先頭の文字を取り除くためにも使用します。正規表現より速いですか?次のコードに何か問題がありますか?
rtrim
ltrim
trim
$string = " hello: "; $string = rtrim(trim($string), ":"); //hello
正規表現を使用した場合、パフォーマンスに違いはありますか?
正規表現は通常、式分析のオーバーヘッドにより、特にこのような小さな文字列に適用すると処理が遅くなります。
左側にコロンが表示されないと仮定すると、以下を削除できますrtrim()。
rtrim()
$string = trim($string, ": "); // trim either space or colon on either side