我在寻找PHP解决方案,我有一些带有一些自定义标记的HTML内容,例如
$html = "he approaches very silently towards him but at the last point of time, the man gets the hint and manages to escape from the attack. ,
[vid] youtubeURL/watch?time_continue=58&v=eED6VRcj1Rs [/vid] What happens in the latter is just breath-taking and comes with a reason why this video has gone viral in such short span of time";
Run Code Online (Sandbox Code Playgroud)
我只想要下面提到的文本的输出:
[vid] youtubeURL/watch?time_continue=58&v=eED6VRcj1Rs [/vid]
or
[vid] youtubeURL/watch?time_continue=58&v=eED6VRcj1Rs [Endvid]
Run Code Online (Sandbox Code Playgroud)
$ FWithReplaceWord将是youtube“ v =” ID eED6VRcj1Rs
需要输出
<div class='embed-responsive embed-responsive-16by9 vid1'><iframe class='embed-responsive-item' src='//www.youtube.com/embed/$FWithReplaceWord' allowfullscreen></iframe></div>
Run Code Online (Sandbox Code Playgroud)
我在用
preg_match_all('~([vid](.*?)[/vid])~', $html, $matches);
Run Code Online (Sandbox Code Playgroud)
但是它不起作用。请帮帮我。
<?php
$html = "he approaches very silently towards him but at the last point of time, the man gets the hint and manages to escape from the attack. , [vid] youtubeURL/watch?time_continue=58&v=eED6VRcj1Rs [/vid] What happens in the latter is just breath-taking and comes with a reason why this video has gone viral in such short span of time";
function getBetweenTwoStrings ($string, $start, $end) {
$string = " ".$string;
$ini = strpos($string, $start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
// Assuming you need in array as well
$tag[0] = "[vid]";
$tag[1] = getBetweenTwoStrings($html, "[vid]", "[/vid]");
$tag[2] = "[/vid]";
echo $tag[0];
echo $tag[1];
echo $tag[2];
?>
Run Code Online (Sandbox Code Playgroud)
[vid] youtubeURL/watch?time_continue=58&v=eED6VRcj1Rs [/vid]
Run Code Online (Sandbox Code Playgroud)
Now you can play around the way you want the output.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
341 次 |
| 最近记录: |