0

I want to fetch data from https://aloostad.com/api/PodcastCourse?Page=1 and show data items in the console but PHP gives me an error.

<?php
// $response = file_get_contents('https://aloostad.com/api/PodcastCourse');
// $response = json_decode($response);
// // $response = new SimpleXMLElement($response);
// echo "<script>console.log(" . $response . " );</script>";

$url = "https://aloostad.com/api/PodcastCourse?Page=1";
$parts = parse_url($url);
$output = [];
parse_str($parts['query'], $output);
// echo $output['page'];
echo "<script>console.log('" . $output['page'] . "');</script>";
?>

This site has Swagger at the URL https://aloostad.com/swagger/index.html

The error is

Notice: Undefined index: page in C:\xampp\htdocs\mamad.php on line 12
tripleee
  • 175,061
  • 34
  • 275
  • 318

2 Answers2

2

Your problem is that you use the wrong keyname!

$url = "https://aloostad.com/api/PodcastCourse?Page=1";
$parts = parse_url($url);
$output = [];
parse_str($parts['query'], $output);
var_dump($output);
// array(1) {
//   ["Page"]=>
//   string(1) "1"
// }

Use $output['Page'], then you should get your value.

CodyKL
  • 1,024
  • 6
  • 14
0
$url = "https://aloostad.com/api/PodcastCourse?Page=1";
$parts = parse_url($url);
$output = [];
parse_str($parts['query'], $output);
echo $output['Page'];
mohamad mazaheri
  • 122
  • 1
  • 12