views:

42

answers:

3

How can I apply regular expression to filter only

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

from the following string

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.

or Without using regular expression and Dom is there anyways to get the same

A: 
preg_match("/\[video[^\]]+\]/i", $subject, $matches);

$matches[0] contains

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

That's a shortcode and you can easily use the WordPress Shortcode API to handle those shortcodes:

function video_shortcode( $atts, $content = null ) {
  // do whatever you want to to
}
add_shortcode('video', 'video_shortcode');

In the $atts array you will have a list of all of your attributes from the video shortcode:

array(
    "src" => "http://duel.evotechaustin.com/wp-content/uploads/2010/09/kramer.m4v",
    "width" => "480",
    "height" => "360",
    "id" => "b-test",
    "class" => "player"
)
Kau-Boy
A: 

Use substring and indexOf

for example,

htmlString = document.getElementById('div').innerHtml();
startIndex = htmlString.indexOf("[video");
endIndex = htmlString.indexOf("]", startIndex);
output = htmlString.substring(startIndex, endIndex);
Codemwnci
Should be difficult to use JavaScript in PHP :)
Kau-Boy