我使用jwplayer替换了youtube视频的youtube网址。从字符串中提取网址然后href
$str='<a href="https://www.youtube.com/watch?v=6anwsDt8AhA"> sometext</a>https://www.youtube.com/watch?v=6anwsDt8AhAApr 19, 2015 - Uploaded by Go FreelancerThis feature is not available right now. Please try again later. Published on Apr 19, 2015. How to get anchor ...How to get anchor text/href on click using jQuery? - YouTube Video for get text from html content jquery other than anchor 4:54 https://www.youtube.com/watch?v=6anwsDt8AhA Apr 19, 2015 - Uploaded by Go Freelancer This feature is not available right now. Please try again later. Published on Apr 19, 2015. How to get anchor ...';
// $disp_question_desc=$content;
$disp_question_desc=str_replace("http", " http", $str);
//get list of youtube urls
preg_match_all('#\b(?:http(?:s)?:\/\/)?(?:www\.)??(?:youtu\.be\/|youtube\.com\/)[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $disp_question_desc, $urls);
if(!empty($urls[0]))
{
foreach($urls[0] as $key=> $youtubeurl)
{
$div_id=$div_container."_".$key;
$youtubeurl=str_replace("/","\/",$youtubeurl);
$youtubeurl=str_replace("?","\?",$youtubeurl);
$youtube_content= "<div class='youtube-videos-container' srcval='".$youtubeurl."'><div class='youtube-videos ".$div_id."' id='".$div_id."' ></div></div>";
$disp_question_desc= preg_replace("/".$youtubeurl."/", $youtube_content,$disp_question_desc,1);
$youtubeurl=str_replace("\\","",$youtubeurl);
if (!preg_match("~^(?:f|ht)tps?://~i", $youtubeurl)) {
$youtubeurl = "https://" . $youtubeurl;
}
}
echo $disp_question_desc;
}
它在正常文本中的youtube url中工作正常。的$我面临的问题,如果在href标记YouTube网址,也被更换的YouTube视频,我需要更换只剩个网址等则href标签
输出网址[0]:
Array
(
[0] => https://www.youtube.com/watch?v=6anwsDt8AhA
[1] => https://www.youtube.com/watch?v=6anwsDt8AhAApr
[2] => https://www.youtube.com/watch?v=6anwsDt8AhA
)
你想替换''内部的网址或标签外? –
外部锚标记,我们需要排除里面,但现在它正在工作的所有链接 –
你需要提取''标记之外的URL吗? –