如何应用正则表达式仅过滤
[video src="http://duel.evotechaustin.com/wp-content/uploads/2010/09/kramer.m4v" width="480" height="360" id="b-test" class="player" ]
来自以下字符串
Is simply dummy text of the printing and typesetting industry.
[video src="http://duel.evotechaustin.com/wp-content/uploads/2010/09/kramer.m4v" width="480" height="360" id="b-test" class="player" ]
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
或者没有使用正则表达式而且Dom无论如何都要获得相同的
答案 0 :(得分:1)
这是一个短代码,您可以轻松使用WordPress Shortcode API来处理这些短代码:
function video_shortcode( $atts, $content = null ) {
// do whatever you want to to
}
add_shortcode('video', 'video_shortcode');
在$atts
数组中,您将获得视频短代码中所有属性的列表:
array(
"src" => "http://duel.evotechaustin.com/wp-content/uploads/2010/09/kramer.m4v",
"width" => "480",
"height" => "360",
"id" => "b-test",
"class" => "player"
)
答案 1 :(得分:0)
preg_match("/\[video[^\]]+\]/i", $subject, $matches);
$matches[0]
包含
[video src="http://duel.evotechaustin.com/wp-content/uploads/2010/09/kramer.m4v" width="480" height="360" id="b-test" class="player"]
答案 2 :(得分:0)
使用substring和indexOf
例如,
htmlString = document.getElementById('div').innerHtml();
startIndex = htmlString.indexOf("[video");
endIndex = htmlString.indexOf("]", startIndex);
output = htmlString.substring(startIndex, endIndex);