Как я могу применить регулярное выражение для фильтрации строки - PullRequest
1 голос
/ 17 сентября 2010

Как применить регулярное выражение только к фильтру

[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 в любом случае получить то же самое

Ответы [ 3 ]

1 голос
/ 17 сентября 2010

Это короткий код, и вы легко можете использовать 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 голосов
/ 17 сентября 2010

Используйте подстроку и indexOf

, например,

htmlString = document.getElementById('div').innerHtml();
startIndex = htmlString.indexOf("[video");
endIndex = htmlString.indexOf("]", startIndex);
output = htmlString.substring(startIndex, endIndex);
0 голосов
/ 17 сентября 2010
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"] 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...