Php preg\u replace\u回调\u数组出现问题
下面的函数检查多个已解析的正则表达式,但它不起作用,我无法发现哪里出错了Php preg\u replace\u回调\u数组出现问题,php,regex,preg-replace-callback,Php,Regex,Preg Replace Callback,下面的函数检查多个已解析的正则表达式,但它不起作用,我无法发现哪里出错了 function getig($string) { $string = preg_replace_callback_array( [ "/\[instagram=(.+?)\]/" => function($matches) { $pid=$matches[1]; $result = fetchData("https://api.instagram.com/oembed/?url=$pid"
function getig($string)
{
$string = preg_replace_callback_array(
[
"/\[instagram=(.+?)\]/" => function($matches) {
$pid=$matches[1];
$result = fetchData("https://api.instagram.com/oembed/?url=$pid");
$result = json_decode($result);
return $result->html; },
"/https?\:\/\/(?:www.)?instagram.com\/p\/(.+\/?)/" => function($matches)
{
$pid=$matches[1];
$urlen=urlencode($url);
$result = fetchData("https://api.instagram.com/oembed/?url=https://instagr.am/p/$pid");
$result = json_decode($result);
return $result->html; },
"#\[ig\](.*?)\[/ig\]#is" => function($matches) {
$pid=$matches[1];
$result = fetchData("https://api.instagram.com/oembed/?url=$pid");
$result = json_decode($result);
return $result->html; }
], $string);
return $string;
}
唯一让我印象深刻的是
.com
中的点不是逃脱。它可能应该是,否则它是匹配的元字符
除了纽琳的什么都行 以前
https?\://
(?: www . )?
instagram . com/p/
( .+ /? ) # (1)
之后
https?://
(?: www \. )?
instagram \. com/p/
( .+ /? ) # (1)
串起
“/https?:\/\/(?:www\)?instagram\.com\/p\/(.+\/?)/”
我的代码中没有错误。我出错的地方是PHP5.6上的am和preg_replace_callback_array()仅在PHP7中可用。请用您得到的预期结果或错误编辑问题,我们不是来猜测您想要达到的目的。