$.get in PHP - Turn JS into PHP
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I can do this in JS but how do I do exactly the same in PHP?


$(document).ready(function() {

function sceneQueryGetAnswer() {
function(data) {
var myOne = data.id;
for (var x = 0; x < data.properties.length; x++) {
if (data.properties[x].name == "Price") {
var myTwo = (data.properties[x].value);

you can't simply convert js into php, js works client side, php server side; but you can replicate that feature via curl. The user Kehet has already provided a good solution.
Stefano Balzarotti 1 year ago
awarded to Kehet

Crowdsource coding tasks.

2 Solutions

Winning solution

You could use curl like this


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://digitaldraping.picarioxpo.com/xpo/api/v2/scenes/1737?api_key=f6c9f58215234710916fe8c4f2c1affa");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);

$json = json_decode($output);

echo $json->id . "<br>\n";

foreach ($json->properties as $property) {
    if($property->name == "Price") {
        echo $property->value . "<br>\n";
Thank you exactly what I wanted!
Jacknumpty 1 year ago

$api = "https://digitaldraping.picarioxpo.com/xpo/api/v2/scenes/1737?api_key=f6c9f58215234710916fe8c4f2c1affa";
$result = file_get_contents($api);
$arr = json_decode($result, true);
$price = array();
foreach ($arr['properties'] as $prop){
if($prop['name'] == "Price"){
$price[] = $prop['value'];
echo json_encode(array('id' => $arr['id'], 'prices' => $price));

This returns a JSON encoded array as PHP can't alter Page elements

View Timeline