2010-09-17 35 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