php 字符串操作

WBOY
Release: 2016-06-23 14:03:08
Original
1043 people have browsed it

$getstr="id=189,pc=0,pt=0,valide=1\r\nid=176,pc=0,pt=0,valide=1\r\nid=177,pc=0,pt=0,valide=1\r\n";
Copy after login



我想以 \r\n 的形式来划分字符串,得到一个数组,然后用键值对的形式来取值,
比如取第一个id的值
$getid=$arr["id"]

求大牛指点


回复讨论(解决方案)

来个2一点的 替换 \r\n 成 , 然后还原成数组...其他的...你看着办

来个2一点的 替换 \r\n 成 , 然后还原成数组...其他的...你看着办


能否贴点代码。大牛哥。。

explode("\r\n", )
explode(",", )

$getstr = "id=189,pc=0,pt=0,valide=1\r\nid=176,pc=0,pt=0,valide=1\r\nid=177,pc=0,pt=0,valide=1\r\n";foreach(explode("\r\n", $getstr) as $row) {  if($row) {    parse_str(strtr($row, ',', '&'), $t);    $res[] = $t;  }}echo $res[0]['id'];
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template