1

i want cache from json result from a curl but getting error function grabe($url,$dir,$rename,$time='0',$format='json') {

$tmp_dir = 'cache';
$dir=$tmp_dir.$dir;
$rename=md5($rename);
$file=$dir.'/'.$rename.'.'.$format;
if(!is_dir($dir)) {mkdir($dir, 0755);}
$cachetime=(60*$time);


if (file_exists($file) && time() - $cachetime < filemtime($file))
{
    $rawdata=file_get_contents($file);
    return $rawdata;
}else
{
    $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$uaa = $_SERVER['HTTP_USER_AGENT'];
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: $uaa");
$rawdata=curl_exec ($ch);
curl_close ($ch); 
if($rawdata){
$fp = fopen("$file",'w');
fwrite($fp, $rawdata); 
fclose($fp);     
return $rawdata;
   } 

}}

eror saying output:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function grabe(), 1 passed in /home/hdmoviewap/public_html/index.php on line 182 and at least 3 expected in /home/hdmoviewap/public_html/core/init.php:3 Stack trace: #0 /home/hdmoviewap/public_html/index.php(182): grabe('https://www.goo...') #1 {main} thrown in /home/hdmoviewap/public_html/core/init.php on line 3

my 182 line index.php blew

$grab=grabe('https://www.googleapis.com/youtube/v3/search?key='.$key.'&part=snippet&order=relevance&maxResults=20&q=Latest+Bollywood+Video&type=video');

1 Answer 1

1

That's because you are calling the grabe function only with an url but without values for the dir and rename parameters.

So, you need something like:

$grab=grabe('https://www.googleapis.com/youtube/v3/search?key='.$key.'&part=snippet&order=relevance&maxResults=20&q=Latest+Bollywood+Video&type=video', 'dir', $rename);
Sign up to request clarification or add additional context in comments.

4 Comments

how to fix it dear?
Just pass two more params. You are doing $grab = grabe(url) and you must execute $grab = grabe(url, 'directory', 'rename')
where in 182 line in index.php ?
Yes, add the two parameters at the end of the method

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.