api

02/24/2018 10:32 ahmed1234550#1
what is the best way to read online api data (html)
02/24/2018 10:50 iMostLiked#2
What type of data is the api returning? JSON or plain html?
If it's plain html you could do something like this in php:
Code:
$dom = new DOMDocument();
$dom->loadHTML(file_get_contents($url));

foreach($dom->getElementsByTagName('tr') as $node) { ... }
[Only registered and activated users can see links. Click Here To Register...]

If it's json then:
Code:
$result = json_decode(file_get_contents($url));
echo $result->{"test"};
Instead of file_get_contents you could also use [Only registered and activated users can see links. Click Here To Register...].
02/24/2018 11:01 ahmed1234550#3
Quote:
Originally Posted by iMostLiked View Post
What type of data is the api returning? JSON or plain html?
If it's plain html you could do something like this in php:
Code:
$dom = new DOMDocument();
$dom->loadHTML(file_get_contents($url));

foreach($dom->getElementsByTagName('tr') as $node) { ... }
[Only registered and activated users can see links. Click Here To Register...]

If it's json then:
Code:
$result = json_decode(file_get_contents($url));
echo $result->{"test"};
Instead of file_get_contents you could also use [Only registered and activated users can see links. Click Here To Register...].
its json, i wanna do it in html not php
02/24/2018 11:51 iMostLiked#4
Quote:
Originally Posted by ahmed1234550 View Post
its json, i wanna do it in html not php
You can't process json in html. If you don't want to do it in php you could use javascript.
02/24/2018 12:08 ahmed1234550#5
Quote:
Originally Posted by iMostLiked View Post
You can't process json in html. If you don't want to do it in php you could use javascript.
ye but i can use different ways, like fetch ajax jquery p5js, all can do the job but someone told me i dont recommend jquery for api requests, im new i dont know the differents between them, thats why im asking what should i use
02/24/2018 12:30 iMostLiked#6
Quote:
Originally Posted by ahmed1234550 View Post
ye but i can use different ways, like fetch ajax jquery p5js, all can do the job but someone told me i dont recommend jquery for api requests, im new i dont know the differents between them, thats why im asking what should i use
It depends on what you want to do. But apart from this I'd always process api requests server sided (e.g. php) and return their output with json so that javascript can handle that.
If your goal is making a dynamic website which requests the api more than one time you have to use ajax.
If it's only one request at the beginning (when the page loads) you don't have to use javascript since php loads before the dom.
03/01/2018 13:48 ahmed1234550#7
#close
03/01/2018 15:22 Serraniel#8
#Closed (on request)