当我用json_encode()
in 编码一个数组时PHP
,所有这些都在这里完成,但是当我用json_decode()
它解码时,它给了我stdClass
Object而不是Array.这是我的代码:
echo $json=json_encode(array('a'=>1,'b'=>2));
echo '<br>';
print_r(json_decode($json));
// and the result of PHP script is :
{"a":1,"b":2}
// stdClass Object ( [a] => 1 [b] => 2 )
Run Code Online (Sandbox Code Playgroud)
什么将它从数组转换为对象?
我可以将json编码的字符串传递给url以获取另一个页面上的数据,或者是否存在可以执行某些url编码的任何函数?
我阅读了CodeIgniter关于迁移类的文档.我能够执行迁移但是如何在迁移中使用down()函数?
这是文档中的示例
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_Add_blog extends CI_Migration {
public function up()
{
$this->dbforge->add_field(array(
'blog_id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'blog_title' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'blog_description' => array(
'type' => 'TEXT',
'null' => TRUE,
),
));
$this->dbforge->create_table('blog');
}
public function down()
{
$this->dbforge->drop_table('blog');
}
Run Code Online (Sandbox Code Playgroud)
在我的页面中,我设置了这样的迁移:
class Migrate extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('migration');
}
public function index() …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的文本块; 而且,其内容是:
txt_1(val_1,val_2,val_3). txt_1(val_4,val_5,val_6). txt_2(val_7,val_8,val_9). txt_3(val_10,val_11,val_12). txt_3(val_13,val_14,val_15). txt_4(val_16,val_17,val_18).
并且,在PHP代码中已经存在一个简单的数组:
$my_array = array();
Run Code Online (Sandbox Code Playgroud)
现在,我想解析这个PHP数组,如:
Array
(
[txt_1] => Array
(
[0] => Array
(
[0] => val_1
[1] => val_2
[2] => val_3
)
[1] => Array
(
[0] => val_4
[1] => val_5
[2] => val_6
)
)
[txt_2] => Array
(
[0] => Array
(
[0] => val_7
[1] => val_8
[2] => val_9
)
)
[txt_3] => Array
(
[0] => Array
(
[0] => val_10 …
Run Code Online (Sandbox Code Playgroud) 我写了一个 PHP 脚本,它使用 HTTP POST 请求curl
并执行以下操作,
这是代码:
$ch = curl_init ( $url );
curl_setopt ( $ch, CURLOPT_COOKIE, "cookie=cookie");
curl_setopt ( $ch, CURLOPT_POST, 1);
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ( $ch, CURLOPT_HEADER, 0);
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
// this point
extr ( $response, $param_1, $param_2);
Run Code Online (Sandbox Code Playgroud)
问题是,有时响应大于 1GB,所以 PHP 代码暂停,直到接收到完整响应(如代码所示// this point
),如果接收到格式错误的 HTML,PHP 会产生错误,所以这里所有的事情都需要从头开始.
下面是其余的功能:
function …
Run Code Online (Sandbox Code Playgroud)