php搜索后添加内容 [英] php search and add content after
问题描述
在我的内容中,我有一个短代码"来显示具有不同参数的视频,具体取决于我希望视频的外观.例如:高度、宽度、视频等.
In my content I have a 'shortcode' to display videos with different parameters depending on how I want the video to look. For example: height, width, video, etc.
我可以在php中写什么来搜索[video {paramaters}]
并在其后添加内容?
What can I write in php to search for [video {paramaters}]
and add content after it?
记住 {parameters}
总是不同的.
推荐答案
好吧,当我需要做这样的事情时,我使用 preg_replace 或 preg_replace_callback..
Well, when I need to do something like this i use preg_replace or preg_replace_callback..
function videofunction($input){
//do something here and then:
return $whatever;
}
$content = preg_replace('%\[video(.*?)\]%e', 'videofunction("\\1")', $content);
然后你必须想出逻辑=)
You then have to come up with the logic though =)
只需阅读您的帖子更多...你想保持标签不变,并在它后面添加一些东西..你可以用 preg replace 来做到这一点......像这样:
Just read your post more... You want to leave the tag as is, and add something after it.. You could do this with preg replace.. like this:
function videofunction($input){
$input .= "whatever else";
return $input;
}
preg_replace('%\[video.*?\]%e', 'videofunction("\\0")', $content);
虽然可能不是最好的方法,也许某种偏移捕获会更好?
Probably not the best way to do it though, maybe some kind of offset capture would be better?
这篇关于php搜索后添加内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!