Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何应用正则表达式筛选字符串_Php_Regex_Wordpress - Fatal编程技术网

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:)