我创建了下一个函数来div用它的 id 替换一个 url。
function twitterIzer($string){
$pattern = '~https?://twitter\.com/.*?/status/(\d+)~';
$string = preg_replace($pattern, "<div class='tweet' id='tweet$1' tweetid='$1'></div>", $string);
return $string;
}
当我使用这种类型的 url 时效果很好
https://twitter.com/Minsa_Peru/status/1260658846143401984
但是?s=20当我使用这个 url 时它会检索一个异常值
https://twitter.com/Minsa_Peru/status/1262730246668922885?s=20
我怎样才能删除这个?s=20文本,以使我的功能发挥作用?我所知道的就是我需要改进我的正则表达式模式。谢谢你。