php - Preg_replace '短代码'在 php
问题描述
我有一个包含 [center] 的字符串(带有方括号),然后需要用另一个字符串替换。我确定必须有一种方法可以使用 preg_replace 但无法使其正常工作
解决方案
一个正则表达式对于这样的任务来说太过分了,使用str_replace
$str="I've got a string containing [center] (with the square brackets)";
$new_str=str_replace('[center]','[left]',$str);
echo $new_str; //I've got a string containing [left] (with the square brackets)
推荐阅读
- c# - 具有默认值的枚举扩展方法的通用字符串
- .net-core - EF Power Tools 默认为 pascalcase
- javascript - 如何将这两个数组放在单独的对象中并推送到 JS 中的主数组?
- batch-file - 批处理脚本 - 重写输出
- python - 如何在熊猫中使用 country_converter 将国家代码转换为名称?
- r - 具有 K 个集群和行名注释的热图
- google-chrome - SameSite=none 和不安全的 http cookie 无法在 Chrome 上运行
- javascript - 仅修改 POST XMLHttpRequest 的 headers
- c - 多个 scanf() 用于获取字符串和整数。其中一些被忽视
- python - 使用 Python 和 Selenium 控制 Web 浏览器“消息:没有这样的元素:无法找到元素”(python)