How do i use GET requests using cURL?

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.

See this:

1 Like

And how do i make a code that makes a .txt file with the number returned:

image

Do this:

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:
image

Sorry for bad coding i am a php learner

Did you do this?

1 Like

This is my code:

And here is what it returns:
image

And here is what the original API returns:
image

After your 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'];
echo $number;
1 Like

Now it doesn’t works anymore.


Try this after your curl_close instead.

$number_fromjson = json_decode($resp, true); 
$number = $number_fromjson["favoritesCount"]; 
echo $number;

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.

2 Likes

It works!!!
Finally, how do I import the content of the txt file (php) into my html dashboard?

You can do that two ways:

  1. Remove echo $number; and include the file in your admin dashboard and just use the $number whenever needed (preferred) or
  2. Use $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 $favorites_number and ?> 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:

<h6><?=$favorites_number?></h6>
1 Like

No, you need the <?php and ?> tags.

You really should have a basic knowledge of PHP before attempting something like this.

1 Like

It doesn’t show up
image