php search and add content after

笑着哭i 提交于 2019-12-13 10:25:30

问题


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.

What can I write in php to search for [video {paramaters}] and add content after it?

Keep in mind {parameters} will always be different.


回答1:


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

Edit: 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?



来源:https://stackoverflow.com/questions/6180782/php-search-and-add-content-after

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