Fastest way to replace string in PHP

前端 未结 4 897
暗喜
暗喜 2020-12-07 01:51

I need to replace some string in a PHP code to make it look better. What would be the best way to go about that?

相关标签:
4条回答
  • 2020-12-07 02:30
    preg_replace
    

    Is a good way to go and uses regular expressions so you have flexibility as to how to do it.

    0 讨论(0)
  • 2020-12-07 02:40

    It depends. If str_replace works for your case, I think is faster and less memory consumer than preg_replace

    0 讨论(0)
  • 2020-12-07 02:43

    If you want to replace a string in a lot of files once (e.g., you have something in your source code which you want to replace), sed might be the right tool for the job.

    man sed
    
    0 讨论(0)
  • 2020-12-07 02:49

    The usual suspects would be str_replace and preg_replace.

    0 讨论(0)
提交回复
热议问题