This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 3 years ago.
Im triyng to take some information from a json file,
the code in that page is like this
{"asignaciones":[{"fecha":"LUNES
29/07","horaEntrada":"18:30","horaSalida":"22:30","tienda":" BK Villa
Urquiza"}],"fechaConsulta":"29/07/2019 17:27","legajo":"28907"}
i want to take "29/7", "18:30", "22:30".
For now, i can print all the code in my page, but i want to take only those numbers, there is a way with:file_get_contents?
i'm trying to learn a little more php sorry if this question is oviously simple.
my code now:
$content = file_get_contents('http://proveedores.alsea.com.ar:48080/asignaciones-server/mobile/main/asignaciones/legajos/28907');
echo $content
?>
It looks like the content is a json... Start from this:
$content = file_get_contents('http://proveedores.alsea.com.ar:48080/asignaciones-server/mobile/main/asignaciones/legajos/28907');
$content = json_decode($content);
print_r($content);
Related
This question already has answers here:
How to display json values that are in 2nd level of a multi-dim array?
(3 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 3 years ago.
Need help. I am having trouble solving this json thingy. here's what is on my database
{"img":["images/logo2.png","images/logo.png"]}
I need to decode this images and show it like this
images/logo2.png
images/logo.png
A quick google search will give you this link: json_decode.
$someJson = '{"img":["images/logo2.png","images/logo.png"]}';
$encodeJson = json_decode($someJson, true);
echo $encodeJson['img'][0]; //images/logo2.png
echo $encodeJson['img'][1]; //images/logo.png
Hint: Having a look at the PHP-Manual is not prohibited. ;)
Maybe select your entry from database and put in a variable called $dataBaseEntry then copy paste this code?
$decoded = json_decode($dataBaseEntry, true); //true for associated array
$logos = $decoded['img'];
print_r($logos)
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
I want to apply the regex to extract only the values. I am not getting the perfect one any help
[{"name":"basket ball"},{"name":"foot ball"},{"name":"sports"}]
There's absolutely no need for a regex here. Use json_decode():
$string = '[{"name":"basket ball"},{"name":"foot ball"},{"name":"sports"}]';
$data = json_decode($string, true);
now you have a normal php array $data to get your wanted data from.
like
echo $data[0]['name']; // basket ball
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I have tried, checked many previous topics, and i cant find the way.
Parsing JSON with PHP
There is the answer, but im blind; actually, im a medimu PHP programmer, but im new with Json.
Here is my Json:
{"result":"true","disponible":{"aaa":"0.00001362","bbb":"0.000392","ccc":"0.00788523","ddd":"0.00004443","eee":"0.0001755","fff":"0.1755","ggg":"797.64618376"}}
My code:
$balances = json_encode(get_balances(),true);
print_r($balances);
The screen show my Json, so everything is ok here. Now, i want take the bolded values from the json and assign it to PHP variables.
$variable1 = $balances["disponible"]["bbb"];
$variable2 = $balances["disponible"]["ggg"];
echo "Valor 1: ".$variable1 ."<br>";
echo "Valor 2: ";$variable2 ;
But it dont work. I tried with many combinantions and nothing.
What im doing wrong?
Thanks a lot in advance. Im blocked with this.
Replace: $balances = json_encode(get_balances(),true); with: $balances = json_decode(get_balances(),true); if you are trying to get associative array.
This question already has answers here:
How to get content from specific tags when using file_get_contents
(2 answers)
Closed 8 years ago.
$landings = file_get_contents('http://www.domain.co.uk/page.php');
In the above example URL I want to only select and copy the HTML from a specific element #sidebar-bgbtm
From there I would like to export the HTML as a JSON value.
Is there any way of doing that?
Thanks
If you are familiar with jQuery syntax, PHP Simple HTML DOM might be good place to start
http://simplehtmldom.sourceforge.net/
include('simple_html_dom.php');
$html = file_get_html('http://www.domain.co.uk/page.php');
$result = $html->find('#sidebar-bgbtm', 0)->outertext;
And then export to json:
echo json_encode( array( 'outertext' => $result) );
This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Closed 9 years ago.
I have this link
http://gdata.youtube.com/feeds/api/users/gudjondaniel/uploads?max-results=1
That gives me the latest video from GudjoDaneel but I'd like to print our this title inside a PHP file
<title type='text'>The GD Project S3 | NEVER GIVE UP! | Division 1</title><content type='text'>
I'd appreciate it if someone could help me where to begin. And what I could look up.
I'd suggest looking up SimpleXML. It's easy to use once you get the hang of it, and you can get the title in just four line:
$url = 'http://gdata.youtube.com/feeds/api/users/gudjondaniel/uploads?max-results=1';
$source = file_get_contents($url);
$xml = new SimpleXMLElement($source);
$title = $xml->entry->title;
Do note, though, that $title is a PHP object in this case. If you echo it straight away, it'll be reinterpreted as a string, and everything will be alright. If you plan on doing anything else with it, you'll need to cast it as a string, like this:
$title = strval($title);