开发者

php search and add content after

In my content I have a 'shortcode' to display videos with different parameters depen开发者_运维百科ding 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜