是否可以将 str_replace
方法与正则表达式结合起来,用于在简单的 html < textfield > 输入类型中捕获 url 字符串?
我正在考虑一些简单的事情,比如提示用户进行如下设置:
这是一些文字,点击此链接 here .
显然,“这里”这个词是它之前(或之后,如果有区别的话)的 URL 的一个 href。文本输入来自 MySQL 数据库。
我相信我的解决方案的开始是这样的:
$regex = '';
$pg = $row['pg'];
$pg = str_replace('{regex goes here}', $pg);
但我知道有些东西不见了。 然后我会输出 $pg 段落。
最佳答案
查看 preg_replace
here ,这就是你要找的。p>
// From the documentation.
preg_replace($regularExpression, $replacement, $subject);
关于php - 正则表达式 str_replace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13528337/