如何使用正则表达式从嵌入格式的文本中替换Instagram URL?
let arbitrary_header: AribitraryNumber = res.headers().get::<ArbitraryNumberHeader>().unwrap();
答案 0 :(得分:0)
正则表达式用于匹配字符串,而不是替换或类似的东西。 如果您想将文本转换为嵌入链接,这是一种方法:
<?php
$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';
$words = explode(' ', $text);
$output = array();
foreach ($words as $word) {
if(preg_match('/^https:\/\/www\.instagram\.com\/p\/.{6,}\?/', $word)) {
$code = explode("/", $word)[4];
$word = '<iframe src="//www.instagram.com/p/$code/embed"></iframe>';
}
array_push($output, $word);
}
echo implode(' ', $output);
?>