What regex pattern do I need for this?

前端 未结 5 668
不思量自难忘°
不思量自难忘° 2020-12-22 09:48

I need a regex (to work in PHP) to replace American English words in HTML with British English words. So color would be replaced by colour, meters by metres and so on [I kno

5条回答
  •  礼貌的吻别
    2020-12-22 10:02

    You don't need to use a regex explicitly. You can try the str_replace function, or if you need it to be case insensitive use the str_ireplace function.

    Example:

    $str = "

    Color: red

    "; $new_str = str_ireplace ('%color%', 'colour', $str);

    You can pass an array with all the words that you want to search for, instead of the string.

提交回复
热议问题