Php 如何应用正则表达式筛选字符串
如何仅将正则表达式应用于筛选器Php 如何应用正则表达式筛选字符串,php,regex,wordpress,Php,Regex,Wordpress,如何仅将正则表达式应用于筛选器 [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.ev
[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,有没有办法得到相同的结果
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"]
$matches[0]
包含
[video src="http://duel.evotechaustin.com/wp-content/uploads/2010/09/kramer.m4v" width="480" height="360" id="b-test" class="player"]
这是一个短代码,您可以轻松使用来处理这些短代码:
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"
)
这是一个短代码,您可以轻松使用来处理这些短代码:
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"
)
使用substring和indexOf 比如说,
htmlString = document.getElementById('div').innerHtml();
startIndex = htmlString.indexOf("[video");
endIndex = htmlString.indexOf("]", startIndex);
output = htmlString.substring(startIndex, endIndex);
使用substring和indexOf 比如说,
htmlString = document.getElementById('div').innerHtml();
startIndex = htmlString.indexOf("[video");
endIndex = htmlString.indexOf("]", startIndex);
output = htmlString.substring(startIndex, endIndex);
在PHP中难以使用JavaScript:)在PHP中难以使用JavaScript:)