正则表达式str_replace [英] Regex str_replace

查看:127
本文介绍了正则表达式str_replace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将str_replace方法与正则表达式结合使用,该方法旨在捕获简单html<中的url字符串.文本字段>输入类型?

Would it be possible to incorporate a str_replace method with a regular expression, designed to catch url strings in a simple html < textfield > input type?

我正在考虑一些简单的技巧(如提示),以供用户按照以下说明进行设置:

I'm considering something simple like a tip for the user to set it up as follows:

这是一些文本,然后单击此链接 此处 .

显然,这里"一词是指向该网址之前(或之后的网址,如果有区别的话)的href.输入的文本来自MySQL数据库.

Obviously the word "here" is a href to the url before it (or after it, if that makes a difference). The text input is drawn from a MySQL db.

我相信我的解决方案的起点是:

I believe the start of my solution is something along the lines of:

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

但是我知道事情不见了. 然后我将输出$ pg段落.

But I know things are missing. And then I would just output the $pg paragraph.

推荐答案

查看preg_replace 此处,这就是您要查找的内容.

Check out preg_replace here, this is what you are lookin for.

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

这篇关于正则表达式str_replace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆