Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I generate this structure file JSON from PHP script?
Example JSON:
{
"messages":[
{
"attachment":{
"type":"image",
"payload":{
"url":"#"
}
}
}
]
}
Thanks :)
That should work.
$a = ["messages" => [["attachment" => ["type" => "image", "payload" => ["url" => "#"]]]]];
$b = json_encode ($a);
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 months ago.
Improve this question
fibStr(3, ["j", "h"]) ➞ "j, h, hj"
fibStr(5, ["e", "a"]) ➞ "e, a, ae, aea, aeaae"
fibStr(6, ["n", "k"]) ➞ "n, k, kn, knk, knkkn, knkknknk"
I just want a function that returns a response like : "n, k, kn, knk, knkkn, knkknknk"
Please try below code will help you:
<?php
function fibStr($n, $arr) {
$resp = $arr;
for($ij= 2;$ij<$n;$ij++)
{
$resp[$ij] = $resp[$ij-1].$resp[$ij-2];
}
return implode(", ",$resp);
}
echo fibStr(6, ["n", "k"]);
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
{
"data": {
"orderId": "10946506",
"status": "FAILED",
"mobile": "9795681183",
"amount": "100.00",
"transId": "",
"error_code": "119",
"service": "Airtel",
"bal": "",
"creditUsed": "0",
"resText": "Ip 185.27.134.67 Not Configured",
"gstMode": "P2P",
"tdsAmount": "0"
}
}
You can do that using PHP native function json_decode, here the example :
<?php
$json ='{"data":{"orderId":"10946506","status":"FAILED","mobile":"9795681183","amount":"100.00","transId":"","error_code":"119","service":"Airtel","bal":"","creditUsed":"0","resText":"Ip 185.27.134.67 Not Configured","gstMode":"P2P","tdsAmount":"0"}}';
$result = json_decode($json);
//Array
print_r($result);
//single data
echo $result->data->orderId;
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
The website http://tracker.ets2map.com/v2/fullmap contains the data I wish to retrieve every 10 seconds using the following code:
<?php
$content = file_get_contents("http://tracker.ets2map.com/v2/fullmap");
$result = json_decode($content);
print_r($result);
I wish to get the info in the form
[{"name":"\u0420\u041e\u0421\u0421\u0418\u042f","x":-11409,"y":11749,"id":73469},{"name":"NikJZX","x":-12305,"y":-6239,"id":401390},{"name":"Efremov777","x":-12390,"y":-5636,"id":1755318}, ...]
But using the code above the data is all scrambled
Thanks for any help.
Edit:
I realise now that scramble is very misleading.
I have fixes my original problem, but now the data returns with a / in it.
Eg.
"{\"Trucks\": {\"1743637\": {\"name\": \"benanayan2\", \"h\": 0.55, \"p_id\": \"2043\", \"server\": 2, \"mp_id\": 1743637, \"t\": 1511366599, \"online\": true, \"y\": -27679, \"x\": 7203}, \"1229525\": {\"name\": \"BoeinGTranSErtu\u011frul15\", \"h\": 2.81, \"p_id\": \"868\", \"server\": 2, \"mp_id\": 1229525, \"t\": 1511366599, \"online\": true, \"y\": -9884, \"x\": -8956}, \"1717847\": {\"name\": \"[VNS] PH\u1ea0M \u0110I\u1ec6P\", \"h\": 2.2, \"p_id\": \"176\", \"server
<?php
$content = file_get_contents("http://tracker.ets2map.com/v2/fullmap");
$result = json_decode($content,true);
echo '<pre>';
print_r($result);
I think you mean that your print_r messes the data in printing. Try my code to get the data print clear and readable. And also when you decode to array , use true , otherwise you end up with an std class object not easily parsed.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I declared one variables like this
echo $OPTIONS="500=>250.00, 1000=>500.00,2500=>1100.00,5000=>2250.00";
and
I got this variables through file_get_contents() functions.
$contents = file_get_contents(SERVICE_URL."options_config.php?options=".$OPTIONS);
$package=array($contents)
foreach($package as $pack=>$price)
{
echo $pack;
}
But I got 0 values. What is the problem?
print_r($package);
The result is :
Array ( [0] => 500=>250.00, 1000=>500.00,2500=>1100.00,5000=>2250.00 )
I want the result like this
500 as 250.00
1000 as 500.00
I think what you are looking for is serialize and unserialize
Example: test.php
<?php
// Handle Get Request
// This portion of your code can be on another file
//
if (isset($_GET['getOptions']))
{
$myOptions = array(
500 => 250.00,
1000 => 500.00,
2500 => 1100.00,
5000 => 2250.00
);
exit(serialize($myOptions));
}
// Sample Usage
$options = file_get_contents('http://localhost/test.php?getOptions');
$options = unserialize($options);
// Debug
var_dump($options);
?>
Outputs:
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
public function run() {
$this->step = $this->$_POST("step", 1);
$this->xml = new XMLFile();
$common_data = array(
'STEPCONTENT' => $this->get_step_content(),
'STEPNUMBER' => $this->step,
'STEPTITLE' => $this->get_step_title()
);
echo $this->parse($this->common_template, $common_data);
This gives the exception:
Fatal error: Method name must be a string in
C:\xampp\htdocs\test\openad\install\InstallOpenAdServer.php on line 674
Why?
This is the culprit
$this->step = $this->$_POST("step", 1);
You cannot use an $_POST super global array as a function. If you are trying to access the vairable from the $_POST, you can simple do this
$this->step = $_POST["step"];