This question already has answers here:
Parse query string into an array
(12 answers)
Closed 3 years ago.
$postdata = file_get_contents("php://input");
this code give value like given below
string(53) "user_name=test&password=471476&sessionId=1&userType=1"
I need to insert the values in table.
how can I insert the values?
$keywords = preg_split("/[\s,]+/", $postdata);
print_r($keywords);
Theres a builtin function:
parse_str()
This question already has answers here:
How to convert array values to lowercase in PHP?
(10 answers)
Closed 5 years ago.
I have this array and I'm currently researching on how to make the contents of the output lowercase.
foreach ($city_info['links'] as $bikes => $url) {
echo '<span> '.$bikes.'</span>';
}
echo '<span> '. strtolower($bikes) .'</span>';
https://www.w3schools.com/php/func_string_strtolower.asp
This question already has answers here:
comma-separated string to array
(3 answers)
Closed 8 years ago.
$MyValue = "1111,5555";
I want result this.
$Value_1 = "1111";
$Value_2 = "5555";
Please help me.
You can use explode():
$MyValue = '1111,5555';
$MyValue = explode(',', $MyValue);
echo $MyValue[0]; //1111
echo $MyValue[1]; //5555
See demo
This question already has answers here:
PHP string to array
(4 answers)
Closed 8 years ago.
I have a complete string how can i get some part of it and insert into an array this is my string in php
[{"albumid":"ASaBFzCtl8","albumname":"anni","type":"3","access":"2","itemcount":"2"},{"albumid":"EmgsZ43ehT","albumname":"testalbum","type":"1","access":"1","itemcount":"0"},{"albumid":"Jf4H4SvFGk","albumname":"test2album","type":"3","access":"1","itemcount":"0"},{"albumid":"k3pacBSmIl","albumname":"testalbumpvt","type":"3","access":"2","itemcount":"0"}]
i want something similar to this
$value1 = $array[0];
// {"albumid":"ASaBFzCtl8","albumname":"anni","type":"3","access":"2","itemcount":"2"}
is this possible to get each value like this
$value1 = $array[0]['albumid'];
// ASaBFzCtl8
Yes use json_decode()
$j = '[{"albumid":"ASaBFzCtl8","albumname":"anni","type":"3","access":"2","itemcount":"2"},{"albumid":"EmgsZ43ehT","albumname":"testalbum","type":"1","access":"1","itemcount":"0"},{"albumid":"Jf4H4SvFGk","albumname":"test2album","type":"3","access":"1","itemcount":"0"},{"albumid":"k3pacBSmIl","albumname":"testalbumpvt","type":"3","access":"2","itemcount":"0"}]';
$data = json_decode($j,true);
You can use loop to read the data as
foreach($data as $key=>$val){
echo $val["albumid"]."<br />";
}
Above will just get the albumid you can read whatever you want from this array.
This question already has answers here:
Add a prefix to each item of a PHP array
(7 answers)
Closed 9 years ago.
I have an array in PHP:
$pbx01_connection = array("customer/voip_extensions.php");
how can i add a prefix and suffix to each item in the array?
for example,
$pbx01_connection = '/admin/'.array("customer/voip_extensions.php");
so /admin/ is added before each item in the array?
Use array_map():
<?php
function addPrefix($value)
{
return '/admin/' . $value
}
$new_array = array_map("addPrefix", $array);
print_r($new_array);
?>