首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Youtube iframe转换为amp-youtube标签

如何将Youtube iframe转换为amp-youtube标签
EN

Stack Overflow用户
提问于 2018-05-14 14:27:20
回答 1查看 2.1K关注 0票数 1

代码语言:javascript
复制
<?php

$content_description = '<p><iframe width="854" height="480" src="https://www.youtube.com/embed/xcJtL7QggTI" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> “While I’ve been very fortunate to have strong mentors and supporters throughout my career, on occasions I’ve encountered a challenge in getting recognition for my work and performance in the form of promotion. Early in my career, a female co-worker and I were in senior manager roles and doing director-level work, but weren’t getting promotions. When we asked the CMO, who was a man, why we weren’t being promoted, he said we were both too young to be directors. At that point, we were already managing teams of five to six people and responsible for driving significant portions of the business, while many directors had smaller teams and fewer responsibilities than us. I started looking for other opportunities outside the company, and when a female VP and colleague heard I was about to leave the company, she offered me a position on her team as director, product management. This gave me a new experience and the director title I had earned. But it’s not just about the title – it’s about being recognized for the business results I was driving and the level of contributions I could bring to any team.</p>
<p><iframe width="854" height="480" src="https://www.youtube.com/embed/TxbE79-1OSI" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>“In the past, I have had assumptions made about the extent of knowledge and expertise I might possess in the space, and this bleeds through to the amount of weight given to my ideas and opinions. You will always encounter initial biases based off of your gender, ethnicity, and perceived identity – but you just have to stick to your guns and remain confident in your voice. The people who talk the loudest aren’t necessarily the smartest in the room. I’ve found the best way to win over those critical of you is to just take action, measure results, and show that you can think analytically and creatively outside the norm of what has already been done.”</p>';

?>

我需要把所有的iframes转换成AMP格式,这样它就会看起来像。

代码语言:javascript
复制
<amp-youtube
    data-videoid="xcJtL7QggTI"
    layout="responsive"
    width="480" height="270">
</amp-youtube>

代码语言:javascript
复制
<amp-youtube
    data-videoid="TxbE79-1OSI"
    layout="responsive"
    width="480" height="270">
</amp-youtube>
EN

回答 1

Stack Overflow用户

发布于 2018-05-15 08:27:00

通过使用str_replace()preg_replace(),您可以实现您的目标

  1. 从内容优先替换https://www.youtube.com/embed/
  2. 获取src值并在内容中替换

下面是工作网址:Click Here

代码:

代码语言:javascript
复制
<?php
$content_description = '<p><iframe width="854" height="480" src="https://www.youtube.com/embed/xcJtL7QggTI" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> “While I’ve been very fortunate to have strong mentors and supporters throughout my career, on occasions I’ve encountered a challenge in getting recognition for my work and performance in the form of promotion. Early in my career, a female co-worker and I were in senior manager roles and doing director-level work, but weren’t getting promotions. When we asked the CMO, who was a man, why we weren’t being promoted, he said we were both too young to be directors. At that point, we were already managing teams of five to six people and responsible for driving significant portions of the business, while many directors had smaller teams and fewer responsibilities than us. I started looking for other opportunities outside the company, and when a female VP and colleague heard I was about to leave the company, she offered me a position on her team as director, product management. This gave me a new experience and the director title I had earned. But it’s not just about the title – it’s about being recognized for the business results I was driving and the level of contributions I could bring to any team.</p>
            <p><iframe width="854" height="480" src="https://www.youtube.com/embed/TxbE79-1OSI" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>“In the past, I have had assumptions made about the extent of knowledge and expertise I might possess in the space, and this bleeds through to the amount of weight given to my ideas and opinions. You will always encounter initial biases based off of your gender, ethnicity, and perceived identity – but you just have to stick to your guns and remain confident in your voice. The people who talk the loudest aren’t necessarily the smartest in the room. I’ve found the best way to win over those critical of you is to just take action, measure results, and show that you can think analytically and creatively outside the norm of what has already been done.”</p>';


$content = str_replace("https://www.youtube.com/embed/","",$content_description);

$html = preg_replace('/<iframe\s+.*?\s+src=(".*?").*?<\/iframe>/', '<amp-youtube
    data-videoid=$1
    layout="responsive"
    width="480" height="270"></amp-youtube>', $content);

echo $html;
?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50332769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档