How to modify the value specified in json in php

藏色散人
Release: 2023-03-02 11:42:02
Original
3740 people have browsed it

How to modify the value in json in php: first set the "curl_setopt" option, including the URL; then execute and obtain the content of the HTML document; and finally release the curl handle.

How to modify the value specified in json in php

php modifies the value specified in json

<?php
header("content-type:text/html;charset=utf-8");
$postid=$_REQUEST[&#39;postid&#39;];
$url ="";
    $ch = curl_init();
    //设置选项,包括URL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //执行并获取HTML文档内容
    $output = curl_exec($ch);
$arr = json_decode($output,true);
    $getcom=$arr[&#39;auto&#39;][0][&#39;comCode&#39;];
include_once("kuaidi_config.php");
$url ="";
    //设置选项,包括URL
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    //执行并获取HTML文档内容
    $output = curl_exec($ch);
    //释放curl句柄
    curl_close($ch);
$obj=json_decode($output, true);
foreach($obj as $key=>$value){
$obj[&#39;com&#39;]="中通";
}
echo json_encode($obj);
?>
Copy after login

For more related knowledge, please visit PHP Chinese net!

The above is the detailed content of How to modify the value specified in json in php. For more information, please follow other related articles on the PHP Chinese website!

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