Home

You are not logged in.
Language: French

#1 2016-09-15 11:56:59

kamykazz
Map maker

[Solved] api script php

hello, looking for a php script to retrieve the variable of API,
I'm struggling!

Code:

<p>
   MapName :
</p>
<form action="" method="post">
<p>
    <input type="text" name="mapname" />
    <input type="submit" value="Valider" />
</p>
</form>
<?php
$mapName = $_POST['mapname'];
$url = 'http://api.urtjumpers.com/?key=************&format=json&liste=maps&field=pk3&query=' . $mapName . '';
$json = file_get_contents($url);
$json_data = json_decode($json);
echo "mapname:". $json_data["pk3"];
?>

an idea?

Last edited by kamykazz (2016-09-15 13:23:21)

Offline

  • Top

#2 2016-09-15 15:25:18

kamykazz
Map maker

Re: [Solved] api script php

problem solved!!!

Code:

<p>
   MapName :
</p>
<form action="index.php?file=*******" method="post">
<p>
    <input type="text" name="mapname" />
    <input type="submit" value="Valider" />
</p>
</form>
<?php
$mapName = $_POST['mapname'];
$fichier = 'http://api.urtjumpers.com/?key=***********&liste=maps&format=xml';
$xml = simplexml_load_file($fichier);
foreach($xml as $map){
    if ($mapName == $map->pk3){    
        echo 'mapname: '. $map->pk3.'<br>';    
        echo 'mapper: '. $map->mapper.'<br>';    
        echo 'way: '. $map->nway.'<br>';    
        echo 'level: '. $map->level.'<br>';
    }
}
?>

Offline

  • Top

#3 2016-09-15 18:02:05

Driller
Moderator

Re: [Solved] api script php

Thanx for posting the solution, Kamykazz zen

Offline

  • Top

#4 2016-09-24 10:12:47

jmarc
webMaster/noobJumper

Re: [Solved] api script php

http://php.net/manual/fr/function.json-decode.php > return an object
if you want an array, add TRUE as 2nd parameter

Offline

  • Top

Board footer

Powered by FluxBB - Adaptation: jmarc
Design: landouille - Icons: famfamfam