Here's the link i want to decode:
https://api.instagram.com/v1/users/28855276/media/recent/?client_id=775829274b6f48c1ac2bf218dda60e16
Actually i've tried many methods to get the result i want but i failed to do so with PHP.
i need to extract a value from this json which should equal a certain variable
Example:
$variable = json_value
The Hard thing here that i want a duplicated value.
the value i need is:
profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_28855276_75sq_1348344197.jpg"
Do not know how to reach this value.
Here's it's place in the json file
{"username":"zedd","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_28855276_75sq_1348344197.jpg","id":"28855276","full_name":"Zedd"}
Please note that i've the username and id values already known.
Need to extract the profile_picture link to a PHP variable.
Please note: profile_picture is duplicated.
There is no duplication by me.
<?php
$array = json_decode('{"username":"zedd","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_28855276_75sq_1348344197.jpg","id":"28855276","full_name":"Zedd"}',true);
echo $array['profile_picture'];
?>
Related
So i am using this PHP code to create the json output, and I am having an issue where it’s creating an array of array with the info. I would like to get rid of one array and just display the list of API’s thats been used and number that has been used.
Looks as though the difference is you have...
"apis":[{"item_search":"0\n"},{"item_recommended":"0\n"}]
and want
"apis":{"item_search":"0\n","item_recommended":"0\n"}
If this is the case, you need to change the way you build the data from just adding new objects each time to setting the key values directly in the array...
$zone_1 = [];
foreach($zone_1_apis as $api_name ) {
$zone_1[substr($api_name, 0,-5)] = file_get_contents('keys/'.$_GET['key'].'/zone_1/'.$api_name);
}
You also need to do the same for $zone_2 as well.
It may also be good to use trim() round some of the values as they also seem to contain \n characters, so perhaps...
trim(file_get_contents('keys/'.$_GET['key'].'/zone_1/'.$api_name))
While retrieving values from array without index in PHP I am getting nothing.
From my database value is stored like ["SCHOOL"] and I want to get just SCHOOL from this.
It's not treated as array instead it's treated as a string.
What will be the solution if want to treat this as array and get value of that array.
My Code is as follows :
$stream_arr = $res_tbl['streams'];
which gives result as ["SCHOOL"]
and I want just SCHOOL from this.
I am using code as $stream = $stream_arr[0];
and I get '[' this as result.
If I assign manual value to $stream_arr = ["SCHOOL"],
above code works and returns SCHOOL as expected.
But for results from my database is not working where result is same as the one I manually assigned.
To eliminate braces from the string you can use below code.
$stream_arr = '["SCHOOL"]';
$temp=explode('"',$stream_arr);
$val=$temp[1];
echo $val; //it will dispaly 'SCHOOL'.
But check the insert query(from the place you store data into db) that why it is storing with braces? if it is done by you as required then proceed else first fix that issue instead of eliminating braces in php code.
I am making a dashboard using php and displaying it on webpage using html. For this I am taking some count values. Is !$value[" variable"] valid in php? How do i get the not of (!=) value? There is no other way to get the data. I am getting the values from a database.
print "<td><a href=\"$strBase and status!='Closed'\" target=\"_blank\">".$value[" ? "]."</td>";
I need to print !closed. Somehow I do not know how to pass that inside $value[].
If you want to use a variable as a key in order to retrieve a value from an array you can do as follows (I use a snippet of your code):
.$value[$myVar].
Where $myVar should be a string with the name of the key you want to retreive from $value
But anyhow, your question is pretty unclear so I'm not sure if this is what you are looking for.
You can check if the variable is empty(), i.e.:
if(empty($value["variable"])){
echo "variable is empty";
}
I'm trying to get data from facebook. So I try to get the user_id from their arrays.
Problem is some user_id are SO LONG that when I try to get it it returns something like
1.00003247906E+14
instead of
100003247905698
How do I fix this? I need the actual user_id.
I tried using:
$targets = (string)($status->actor_id);
But its still returning the same.
You can try $targets = sprintf('%0.0f',$status->actor_id)
A quick fix of this :
printf("%14.0f", 1.00003247906E+14);
will print
100003247905698
$targets = (string)($status->actor_id); must be returning and invalid value, because the invalid value must already be inside $status
Are you actually printing the retrieved user_id directly (like via print_r($status))?
I'm getting a few rows from the DB with an ajax call in PHP and I save the result to an array with javascript.
Then I make some changes in the data and wish to update the DB.
So I use another ajax call for that but I can't manage to access the fields inside the rows correctly.
When I try this I get nothing:
echo $bArray[$i].branchId;
When I try this:
echo json_encode($bArray[$i].branchId);
I get ArraybranchId instead of the field value.
What's the correct way to access the field with php?
Try either for array:
$bArray[$i]['branchId']
or for object:
$bArray[$i]->branchId
depending which type $bArray[$i] is (array or object). You have not written in your question, so I showed both ways.
I take it branchId is the name of the field, and you want the value for that field?
If so, it's:
echo $bArray['branchId']; or
echo $bArray[$i]['branchId']
Edit: Also, you'll need to make sure you're using mysql_fetch_assoc not mysql_fetch_array!