-2

The function below checks for multiple regex parsed but its not working and i couldn't spot where am getting it wrong.

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;
 }
Omotayo
  • 59
  • 6
  • Please Edit the question with the desired result or errors you get, we are not here to guess what you are trying to achieve. – Omri Luzon Jun 03 '17 at 01:11

2 Answers2

0

The only thing that sticks out to me is that the dot in .com is not
escaped. It probably should be, otherwise it is a metacharacter that matches
anything but newline's.

Before

 https?\://
 (?: www . )?
 instagram . com/p/
 ( .+ /? )                     # (1)

After

 https?://
 (?: www \. )?
 instagram \. com/p/
 ( .+ /? )                     # (1)

Stringed

"/https?:\/\/(?:www\.)?instagram\.com\/p\/(.+\/?)/"

0

There is no error in my code. Where am getting things wrong is that am on PHP5.6 and preg_replace_callback_array() only available in PHP7.

Omotayo
  • 59
  • 6