- preg_replace_callback: documentation ( source)
- trim: documentation ( source)
<?php
$body = '<blockquote class="twitter-tweet" data-lang="ja"><p lang="en" dir="ltr">Thank you ! ~ that is all :) <a href="https://t.co/4evflUT84g">pic.twitter.com/4evflUT84g</a></p>— Chicago Police (@Chicago_Police) <a href="https://twitter.com/Chicago_Police/status/877727536125419520">2017年6月22日</a></blockquote><script async="" src="//platform.twitter.com/widgets.js" charset="utf-8"></script>';
$body = preg_replace_callback('!(https://twitter.com/[^/]+?/status/\d+)!s', function ($matches) {
return '[[embed-twitter]](' . trim($matches[1]) . ')';
}, $body);
$body = preg_replace_callback('!(<blockquote class="twitter-tweet" data-lang="ja">.*?</blockquote>)!s', function ($matches) {
return '[[embed-twitter]](' . trim($matches[2]) . ')';
}, $body);
echo $body;
?>