Regex str_replace

限于喜欢 提交于 2019-12-18 05:40:33

问题


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:

This is some text and click this link here.

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);

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


回答1:


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

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



回答2:


What you're looking for is preg_replace:

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


来源:https://stackoverflow.com/questions/13528337/regex-str-replace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!