首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

php读取文本指定的值

发布网友 发布时间:2022-04-23 21:26

我来回答

2个回答

热心网友 时间:2022-04-07 11:27

你用下面的代码试试:

$json= '{"createForm":{"multiple":1,"shareType":"SELF","title":"","description":"","minSubscriptionCost":"0.00","subscriptionCost":"0.00","commissionRate":"0.00","baodiCost":"0.00","secretType":"FULL_PUBLIC","mode":"COMPOUND","content":"1:02,11\r\n1:01,10\r\n1:01,03\r\n1:08,02\r\n1:01,03\r\n1:05,06\r\n1:08,09\r\n1:02,01\r\n1:07,06\r\n1:07,04","periodId":48308,"units":10,"schemeCost":20,"playType":"RandomTwo"},"lotteryType_key":"sdel11to5","ajax":"true"}';

$data = json_decode($json, true);
$content = $data['createForm']['content'];
// 注意,这里的$content中包含"\r\n",如果你是保存到普通文件,则他本身就是换行符,所以直接将$content保存到文件即可,如果你是在页面中输出,则有两种方式
// 方式1
$contents = explode('\r\n');
foreach ($contents as $v) {
echo $v,'<br />';

}
// 方式2
$content = preg_replace('/\r\n/', '<br />', $content);
echo $content;

热心网友 时间:2022-04-07 12:45

下面的代码运行结果就是你需要的,请参考:


<?php
  $s='{"createForm":{"multiple":1,"shareType":"SELF","title":"","description":"","minSubscriptionCost":"0.00","subscriptionCost":"0.00","commissionRate":"0.00","baodiCost":"0.00","secretType":"FULL_PUBLIC","mode":"COMPOUND","content":"1:02,11\r\n1:01,10\r\n1:01,03\r\n1:08,02\r\n1:01,03\r\n1:05,06\r\n1:08,09\r\n1:02,01\r\n1:07,06\r\n1:07,04","periodId":48308,"units":10,"schemeCost":20,"playType":"RandomTwo"},"lotteryType_key":"sdel11to5","ajax":"true"}';
  $a=json_decode($s,true);
  //print_r($a);
  echo $a['createForm']['content'];
?>

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com