【发布时间】:2018-07-27 19:07:20
【问题描述】:
如何用正则表达式替换嵌入格式文本中的 Instagram URL?
//Input
$text = 'There is https://www.instagram.com/p/Bes0orNjOIa/?taken-by=kendalljenner and then there was https://www.instagram.com/p/BZMh9qgl8Kw/?taken-by=felix.gaebler';
//Expected output
$text = 'There is <iframe src="//www.instagram.com/p/Bes0orNjOIa/embed"></iframe> and then there was <iframe src="//www.instagram.com/p/BZMh9qgl8Kw/embed"></iframe>';
【问题讨论】:
-
你的目标到底是什么?正则表达式用于匹配
Strings,而不是替换或类似的东西。 -
$text = It was...如果这是您的真实代码,则会向您抛出undefined constant警告。 -
这个问题不清楚,原因太多了。
-
@FelixGaebler 我想为 URL Instagram 应用嵌入模式。
-
@FunkFortyNiner 当然,我知道)
标签: php regex curl instagram embed