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.
我有一个脚本,我可以在其中使用substr()或str_replace()。我substr()只需要切断最后一个字符,而使用 str_replace 我需要!什么都不替换。哪个会更快?
substr()
str_replace()
!
我猜substr()?
我对 PHP 源代码不熟悉,但我认为肯定substr()是 ,因为它可以直接跳转到定义的偏移量。
不要忘记,这只会在大量数据的情况下产生影响。对于较小的字符串,最好选择使代码更具可读性的任何内容。