Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
$wiki_img = "http://en.wikipedia.org/w/api.php?action=query&titles=Google&prop=pageimages&format=json&pithumbsize=500";
$json2 = file_get_contents($wiki_img);
$data2 = json_decode($json2, TRUE);
foreach ($data2['query']['pages'] as $pages)
{
print_r($pages['source']);
}
My codes are not working.
But I can't find what is error.
I got this error
"Notice: Undefined index: source in C:\xampp\htdocs\"
As your JSON data which you got is
{
query: {
pages: {
1092923: {
pageid: 1092923,
ns: 0,
title: "Google",
thumbnail: {
source: "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Googleplex-Patio-Aug-2014.JPG/500px-Googleplex-Patio-Aug-2014.JPG",
width: 500,
height: 375
},
pageimage: "Googleplex-Patio-Aug-2014.JPG"
}
}
}
}
It should be..
foreach($data2['query']['pages'] as $value){
echo $value['thumbnail']['source'];
}
Output:
http://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Googleplex-Patio-Aug-2014.JPG/500px-Googleplex-Patio-Aug-2014.JPG
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Have been stuck with this little issue, when using key value arrays inside a class |I will get an error syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']'
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
}
}
I have checked your code in my system there is no any error in your code
<?php
class hello{
public function name(){
$allnames = array("name"=>"mark" , "role" => "admin");
return $allnames;
}
}
$obj = new hello;
print_r($obj->name())
?>
Please check
You may try assign array as
$allnames = ["name"=>"mark" , "role" => "admin"];
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Trying to follow the examples here, but it gives me
Fatal error: Uncaught Error: Call to undefined function sodium_randombytes_buf()
On top of that, the key pairs seems to be generating weird strings like:
kÿòjƒFDú{î—4]F◊߈u…®_•A∞+.
Is that normal?
Here's my code
<?php
// send
$message = 'Hi, this is Alice';
$alice_to_bob_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
file_get_contents('./keys/sec-user-1_box_key.txt'),
file_get_contents('./keys/pub-user-2_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$ciphertext = sodium_crypto_box(
$message,
$nonce,
$alice_to_bob_kp
);
// receive
$bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
// $bob_box_secretkey,
// $alice_box_publickey
file_get_contents('./keys/sec-user-2_box_key.txt'),
file_get_contents('./keys/pub-user-1_box_key.txt')
);
$nonce = sodium_randombytes_buf(SODIUM_CRYPTO_BOX_NONCEBYTES);
$plaintext = sodium_crypto_box_open(
$ciphertext,
$nonce,
$bob_to_alice_kp
);
if ($plaintext === false) {
die("Malformed message or invalid MAC");
}
die($plaintext);
There is no such function as sodium_randombytes_buf() the code in the example uses \Sodium\randombytes_buf().
Edit:
From the bug history:
"The sodium_randombytes_* symbols have been removed a while back, as PHP now provide similar functions without this extension"
Bug #74896 sodium's .h defines some functions without .c implementation
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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
[16-Aug-2013 01:38:56 America/Sao_Paulo] PHP Parse error: syntax error, unexpected '}' in /home/lineage/public_html/includes/templates/activate.php on line 21
Archive:
<?php
if (!isset($included) || !$included) exit();
if ($hash->validate($_GET['serial']))
if ($_handlerLoginServer->exec($_queryLogin['activateAccount'],array($_GET['serial'])) > 0) {
$account = $_handlerLoginServer->select($_queryLogin['accountSerial'],array($_GET['serial']));
if ($cookie->set("referral")) {
if (!$_handlerLoginServer->select($_queryLogin['checkIP'],array($_SERVER['REMOTE_ADDR'])))
$_handlerLoginServer->execute($_queryLogin['increaseReferral'],array($cookie->get("referral")));
$playerInfo = $_handlerLoginServer->select($_queryLogin['selectPlayer'],array($cookie->get("referral")));
if ($playerInfo[3] % 10 == 0) {
$balance->increase($playerInfo[1],$_config['referralReward']);
$log->add($log->format($_lang['log']['referralReward'],array($_config['referralReward'])),$playerInfo[1]);
}
}
$cookie->delete("referral");
}
$log->add($_lang['log']['activatedAccount'],$account[0]);
$_templatePage->replace("feedback",$_lang['success']['activateAccount']);
} else
$_templatePage->replace("feedback",$_lang['error']['activateAccount']);
} else
$_templatePage->replace("feedback",$_lang['error']['serialFormat']);
?>
On Line 4 and 8 you need to add an opening brace
change line 4
if ($hash->validate($_GET['serial']))
to
if ($hash->validate($_GET['serial'])) {
change line 8
if (!$_handlerLoginServer->select($_queryLogin['checkIP'],array($_SERVER['REMOTE_ADDR'])))
to
if (!$_handlerLoginServer->select($_queryLogin['checkIP'],array($_SERVER['REMOTE_ADDR']))) {
Go to line 4, and add an open squiggily bracket:
<?php
if (!isset($included) || !$included) exit();
if ($hash->validate($_GET['serial'])){
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What I have :
I have a software dump data like exactly below file :
DMPDATA = {
["invent1"] = {
["1000:1"] = {
["I"] = "6948",
["C"] = 1,
["G2"] = "0",
["G3"] = "0",
["G1"] = "0",
},
["0000:10"] = {
["I"] = "39622",
["C"] = 1,
["G2"] = "0",
["G3"] = "0",
["G1"] = "0",
},
},
["invent2"] = {
["M:1"] = 60116,
["M:3"] = 32246,
["M:2"] = 41252,
},
["invent3"] = {
["47465"] = 5,
["12970"] = 5,
},
["invent4"] = {
{
["F"] = 0,
["V"] = 0,
["N"] = "Classic",
}, -- [1]
{
["F"] = 16,
["V"] = 3500,
["N"] = "Horde",
}, -- [2]
},
["invent6"] = {
["class"] = "WARRIOR",
["gender"] = 2,
},
}
Question:
I want to parse above data as array , I try to do but don't know whats better way .
How can parse files like above code with PHP to have a all data as Array ?
This looks like LUA code. Have you tried the Lua class in PHP?
http://www.php.net/manual/en/lua.eval.php
Here's a guy that has a similar problem with a WoW Addon Lua file:
I need a tool to parse Lua tables, preferrably in Ruby or Java
EDIT:
Try this tool. It also links to a PHP script you might use. http://fin.instinct.org/lua/
EDIT 2:
This is basically what you need. As you can see you're not the first person who wants to parse WoW Lua dumps to PHP arrays =)
http://fin.instinct.org/lua/lua2phparray.phps