【问题标题】:PHP preg_replace string textPHP preg_replace 字符串文本
【发布时间】:2011-10-11 16:04:31
【问题描述】:

我正在尝试替换以下每个实例:

{{anythinghere::anythingthere}} 

在一个字符串中。

任何帮助将不胜感激

【问题讨论】:

  • 你想用什么替换它们?
  • 假设其余都是文字字符,定义 anything。同时回答 Spudley 的问题。
  • 用什么替换什么?给我示例字符串和想要的结果

标签: php regex string replace preg-replace


【解决方案1】:

由于您没有指定要替换它的内容:

preg_replace("/{{([^:}]+)::([^:}]+)}}/", "First_param: $1, Second_param: $2", $target_string);

这将返回First_param: anythinghere, Second_param: anythingthere

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-05
    相关资源
    最近更新 更多