【问题标题】:Regex str_replace正则表达式 str_replace
【发布时间】:2012-11-23 11:38:07
【问题描述】:

是否可以将str_replace 方法与正则表达式结合起来,旨在捕获简单的html 输入类型中的url 字符串?

我正在考虑一些简单的事情,比如提示用户进行如下设置:

这是一些文字,点击此链接here

显然,“这里”这个词是它之前(或之后,如果有区别的话)的 URL 的一个 href。文本输入来自 MySQL 数据库。

我相信我的解决方案的开始是这样的:

$regex = '';
$pg = $row['pg'];
$pg = str_replace('{regex goes here}', $pg);

但我知道有些东西不见了。 然后我会输出 $pg 段落。

【问题讨论】:

    标签: php mysql regex url str-replace


    【解决方案1】:

    看看preg_replacehere,这就是你要找的。​​p>

    // From the documentation.
    preg_replace($regularExpression, $replacement, $subject); 
    

    【讨论】:

    【解决方案2】:

    你要找的是preg_replace:

    $pg = preg_replace('{regex goes here}', '{replacement goes here}', $pg);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-20
      • 2021-03-21
      • 1970-01-01
      • 2011-05-13
      • 2011-07-04
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      相关资源
      最近更新 更多