PHP串行化(序列化)跟反串行化
PHP串行化(序列化)和反串行化
这个和java的序列话是一样的。只是java要实现Serializable这个空接口。
serialize() 把变量和它们的值编码成文本形式
unserialize() 恢复原先变量
什么情况下需要序列化 当你想把的内存中的对象写入到硬盘 数据库的时候;当你想在网络上传送对象的时候;
当把这些序列化的数据放在URL中在页面之间会传递时,需要对这些数据调用urlencode(),以确保在其中的URL元字符进行处理
也可用array,把一个数组对象系列化。
<?php class Data{ var $index; var $name; function __construct($index,$name){ $this->index = $index; $this->name = $name; } } $data1 = new Data(1, "hello"); $data2 = new Data(2, "world"); $arr = array(); //用ArrayObject也可以。 //$arr = new ArrayObject(); $arr[0] = $data1; $arr[1] = $data2; $str = serialize($arr); $file = fopen("tmp.txt", "w"); fwrite($file, $str); fclose($file); //$file =fopen("tmp.txt", "r"); $data = file_get_contents("tmp.txt"); //反序列化得到原来的数组对象。 $obj = unserialize($data); print_r($obj[0]); echo $obj[0]->name; ?>
tmp.txt的内容为:
a:2:{i:0;O:4:"Data":2:{s:5:"index";i:1;s:4:"name";s:5:"hello";}i:1;O:4:"Data":2:{s:5:"index";i:2;s:4:"name";s:5:"world";}}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: <

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Serialization is the process of converting a data structure or object into a string for storage, transmission, or representation, and conversely, parsing a string into the original data structure or object. In PHP, we can use the serialize() function to serialize a variable into a string, and use the unserialize() function to deserialize a string into a primitive data structure or object. This article will focus on the use and precautions of the PHPunserialize() function. 1. unserialize

The data folder contains system and program data, such as software settings and installation packages. Each folder in the Data folder represents a different type of data storage folder, regardless of whether the Data file refers to the file name Data or the extension. Named data, they are all data files customized by the system or program. Data is a backup file for data storage. Generally, it can be opened with meidaplayer, notepad or word.

PHP is a popular programming language commonly used for web development. Among them, serialize and unserialize are two very useful functions that can convert PHP objects into strings and deserialize them.

The index in MySQL means index. It is a data structure used to speed up the query of database tables. The index can be compared to the catalog of a book. It stores the values of specific columns in the table and the corresponding row positions, making the database more efficient. Locate and access data quickly. The function of the index is to improve query efficiency. Without an index, the database needs to scan the entire table row by row to find matching data. This method will be very time-consuming in large tables. With an index, the database can The required data rows are quickly located in the order, which greatly improves the query speed.

The solution to the garbled mysql load data: 1. Find the SQL statement with garbled characters; 2. Modify the statement to "LOAD DATA LOCAL INFILE "employee.txt" INTO TABLE EMPLOYEE character set utf8;".

PHP source code running problem: Index error resolution requires specific code examples. PHP is a widely used server-side scripting language that is often used to develop dynamic websites and web applications. However, sometimes you will encounter various problems when running PHP source code, among which "index error" is a common situation. This article will introduce some common causes and solutions of index errors, and provide specific code examples to help readers better deal with such problems. Problem Description: When running a PHP program
