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))?
Related
Please help me. how to display only value on Laravel.
when i'm var_dump($data->count_date)
i got like this.
int(347)
how to remove int()?
Thks
php var_dump — Dumps information about a variable, not the variable alone.
$data->count_date is an integer number value, you can use it like any other integer, for example:
$value=$data->count_date+1;
Just do, It will only return the value.
dd($data->count_date);
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 have problem with a json, this json keeps updating, so the last entry will never be the same. This is the json:
{"channel":{"id":274304,"name":"Water","description":"Record water consumption.","latitude":"0.0","longitude":"0.0","field1":"Water","created_at":"2017-05-17T16:27:46Z","updated_at":"2017-05-19T01:01:07Z","last_entry_id":28},"feeds":[{"created_at":"2017-05-19T00:51:35Z","entry_id":1,"field1":"288"},{"created_at":"2017-05-19T00:51:50Z","entry_id":2,"field1":"304"}]}
I have something like this in my php code, where the variable $cool contains the decoded json.
$x= $cool->feeds[2]->field1;
But when the json updates, feeds[2] will not be the last entry. So i was thinking of using arrays to store all data. But i don't know how to do this. Can you help me?
If $cool->feeds is an array as I assume, you can use end to get its last item:
$x = end($cool->feeds)->field1;
If you want to get the last element, you also can use array_pop()
$x = array_pop($cool->feeds)->field1;
$q2=$_REQUEST['binge'];
'book2'=>array('callno'=>123006,'price'=>number_format(844,2),'desc'=>'Binge','auth'=>'Tyler Oakley','quant'=>$q2,'total'=>number_format(844,2)*$q2)
On this particular code, It kept displaying errors like this
Warning: A non-numeric value encountered in C:\xampp\htdocs\Webcard_3new\Webcard\wishlist.php on line 97
I searched all over the net for finding the right answers but some are just so complex to understand...
It supposed to be that $q2 is the variable inside an array. That variable is then multiplied to the "TOTAL". but the errors kept on going.. please help!!
The super-globals will always be strings. You need to explicitly convert them using intval():
$q2 = intval($_REQUEST['binge']);
Also, this line:
'book2'=>array...
Should be
$book2 = array...
You can use
$q2 = filter_var($_REQUEST['binge'], FILTER_VALIDATE_INT);
here you will have the benefit of validation where false is returned when someone passes a value that is not an integer. If it is instead a float use FILTER_VALIDATE_FLOAT instead.
Also, consider using $_GET, or $_POST directly to have more control of the data channel. $_REQUEST cobbles together several things into one, which sometimes may cause issues when more than one channel have the same key.
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'];
?>