How do i use cURL to get a text from a JSON file and then transforming this text into a .txt file?
API Docs: https://games.roblox.com/docs#/
After the .txt file is transformed my admin dashboard (written in html) must get the content from this text file and insert it on the page.
And how do i make a code that makes a .txt file with the number returned:
And then this:
header("Content-Type: text/plain; charset=utf-8");
The .txt convertor works but i can’t figure out how to get JUST the number for the txt:
Sorry for bad coding i am a php learner
This is my code:
And here is what it returns:
And here is what the original API returns:
curl_close($curl), remove the
var_dump(). Then you can type this to return just the number:
$number_fromjson = json_decode($resp);
$number = $number_fromjson['favoritesCount'];
Now it doesn’t works anymore.
Try this after your curl_close instead.
$number_fromjson = json_decode($resp, true);
$number = $number_fromjson["favoritesCount"];
The problem with the code I originally provided is it was being converted into an object instead of an associative array. It no longer has that problem and should be working, I tested it.
Finally, how do I import the content of the txt file (php) into my html dashboard?
You can do that two ways:
echo $number; and
include the file in your admin dashboard and just use the
$number whenever needed (preferred) or
$favorites_number = file_get_contents("https://api.bloxstargames.cf/gba/v1/favorites.php"); and assign it to a variable, such as
favorites_number, like I did above. This is easier, but not really preferred.
But it’s html not php so php functions doesn’t works on html because html is static and php is dynamic
Then just change the file extension to php and do what I said. There’s no easy and efficient way to do that with html.
And if i do that i will also need to remove the html tag or just add the php tags and then the html tags?
(Again sorry but i am a php learner lol)
Just change the extension. If you remove any html tags, you may break your code.
So this should like this:
In the first picture, you need to put
<?php (and a space) before
?> at the end of the line. like this:
<?php $favorites_number = file_get_contents("https://api.bloxstargames.cf/gba/v1/favorites.php"); ?>
For it to display the number, you need to put
<?= so it will actually display the number and then
?>. like this:
No, you need the <?php and ?> tags.
You really should have a basic knowledge of PHP before attempting something like this.