2010-09-17 34 views
1

如何申请一个字符串正则表达式来从以下字符串如何申请正则表达式过滤

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. 

使用或不使用正则表达式过滤仅

[video src="http://duel.evotechaustin.com/wp-content/uploads/2010/09/kramer.m4v" width="480" height="360" id="b-test" class="player" ] 

和DOM有不管怎么说得到相同的

回答

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"] 
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" 
) 
0

使用子和的indexOf

的考试ple,

htmlString = document.getElementById('div').innerHtml(); 
startIndex = htmlString.indexOf("[video"); 
endIndex = htmlString.indexOf("]", startIndex); 
output = htmlString.substring(startIndex, endIndex); 
+0

应该很难在PHP中使用JavaScript :) – 2ndkauboy 2010-09-17 10:34:36