Latest article

How to read Chinese garbled characters in php-PHP problem

The solution to php reading Chinese garbled characters: 1. Modify the encoding type of the PHP page language itself; 2. Select “UTF8” for the MySQL character set; 3. Replace the same editor; 4. Programmatic access to MySQL , just add the code “mysql_query(“SET NAMES & # 39; GBK & # 39;”);”. Recommendation: “PHP Video Tutorial” Causes and Solutions of PHP Chinese Garbled Code Reason: 1. The encoding type of the PHP page language itself is not suitable. At this time, the Chinese you write directly in the script must be garbled, let alone the database; Solution: Select ‘UTF8’ or ‘gb2312’, so that the client’s browser will automatically select and display the correct Chinese. Note: ‘UTF8’ or ‘gb2312’ can display Chinese correctly. 2. The encoding type in the database MySQL is incorrect. Solution: When creating a database, select ‘UTF8’ for the MySQL character set, and select utf8_general_ci for the MySQL connection proofreading. There must be no problem with the database created in this way to store Chinese. Otherwise, your Chinese will be garbled characters in MySQL first, let alone display it correctly in the PHP page for you. 3. It is related to the usual script editing environment. For example, some…

How to convert php array string to string – PHP question

How to convert php array strings to strings: 1. Use the PHP implode function to convert arrays into strings. The syntax is like “implode(glue, pieces)”; string. Recommendation: “PHP Video Tutorial” Two ways to convert PHP array to string Method 1, use the implode function that comes with it Method 2, use the loop to traverse the array elements to stitch them into strings $value) { $str1 .=','.$value; } var_dump($str1); The above is the detailed content of how to convert php array string to string, please pay attention to other related articles on 1024programmer.com for more!

How to intercept garbled characters in php Chinese-PHP problem

The solution to php Chinese interception of garbled characters: first obtain the length of the Chinese string through the mb_strlen function; then use php’s built-in function mb_substr to intercept the string. Recommendation: “PHP Video Tutorial” The solution to garbled characters in Chinese strings intercepted by PHP When there is a need to intercept a string, the first thing that comes to mind is substr(), but there will be garbled characters. So if you want to intercept a Chinese string, you can use PHP’s built-in Chinese function: mb_substr(), This is mb_substr( $str, $start, $length, $encoding ) $str : Chinese characters to be truncated string; $start: interception start parameter, starting from 0; $length: number of words to be intercepted; $encoding: web page encoding, such as UTF-8, GB2312, GBK; In addition, attach a function to obtain the length of the Chinese string to obtain the length of the Chinese character: mb_strlen() mb_strlen( $str, $encoding ) $str : Chinese character string; $encoding : web page encoding, such as UTF-8, GB2312, GBK; The above is the detailed content of how to intercept garbled characters in php Chinese, please pay attention to other related articles on 1024programmer.com for more!

How to solve ajaxphp Chinese garbled-PHP problem

Ajax php Chinese garbled solution: 1. Uniformly use utf-8 encoding for all data; 2. Use the two functions “function JSON($array) {}” and “arrayRecursive” for each The characters are encoded separately. Recommendation: “PHP Video Tutorial” PHP using ajax Chinese garbled problem In php, after extracting data from the database, we generally extract multiple rows of data at a time. If the front-end js uses ajax to interact with the back-end, php can only echo one data, but we have multiple data, So only one array can pass, which uses the json_encode() function. The json_encode() function means to convert the data into json data. Let’s see how to convert, php array: First we create two arrays in php, one contains Chinese, the other contains numbers or English , and finally look at the output. Idea: the associated value is more intuitive $gg=array('a'=>'China', & # 39; b & # 39; => & # 39; Japan & # 39;, & # 39; c & # 39; => & # 39; America & # 39;, & # 39; d & # 39; => 'Canada','e'=>'France'); $yy=array('f'=>'6','g'=>'7','h&#39 ;>='8','i'=>'tom','j'=>'kevin') ; Output only one of the arrays: echo $json=json_encode($gg); Output The result is as follows {“a”:”\u4e2d\u56fd”,”b”:”\u65e5\u672c”,”c”:”\u7f8e \u56fd”,”d”:”\u52a0\u62ff\u5927″,”e”:”\u6cd5\u56fd”} There are…

How to modify php.ini-PHP problem in Linux

How to modify php.ini in linux: first find “php.ini” through the command “php -i | grep 'php.ini'”; then modify the file content; finally restart PHP Can. Recommendation: “PHP Video Tutorial” Modify php.ini file under Linux Find the .ini path #If the PHP environment is installed, you can use the php command ## The first way [root@tt ~/php7]$ php -i | grep 'php.ini' Configuration File (php.ini) Path => /home/root/php7/lib Loaded Configuration File => /home/root/php7/lib/php.ini ## Second way php –ini #If the PHP environment is not installed, use the command that comes with linux find / -name php.ini Restart PHP in Centos After modifying etc/php.ini, you must restart PHP to take effect Method 1 # Find the process number of the master process (/etc/php-fpm.conf) ps aux | grep php-fpm root 4811 0.0 0.0 173300 884 pts/1 S+ 18:39 0:00 grep php-fpm # kill the process kill -QUIT xxxx # restart /etc/init.d/php-fpm If you set permissions and start php-fpm when installing PHP: chmod 755 /etc/init.d/php-fpm /etc/init.d/php-fpm start chkconfig –add php-fpm Method 2 You can also start, stop and restart as a service: service php-fpm start service php-fpm stop service php-fpm reload Some experience #Error log modification length log_errors_max_len = 20480 The above is…

winphp installation tutorial-PHP problem

Win php installation method: first download php; then copy a copy of “php.ini-development”, and rename it “php.ini” and put it in the installation path; then load PHP in Apache; finally configure mysql will do. Recommendation: “PHP Video Tutorial” windows php installation 1 .Download address https://windows.php.net/download 2. Install and configure php In the installation directory, copy a copy of php.ini-development and rename it to php.ini and put it in the installation path Add in the .ini file extension_dir = “c:\php\ext” c:\php is the php installation path 3. Load PHP in Apache Open httpd.conf under conf in the apache installation directory Add LoadModule php7_module C:/php/php7apache2_4.dll AddType application/x-httpd-php.php.html PHPIniDir “c:\php” Create a new file under the Apache installation path\htdocs: test.php Edit inside: Open the apache service in the browser and type http://localhost/test.php to display the apache information 4. Configure mysql Add a line in the php.ini extension section extension=php_mysqli.dll Edit in test.php: The apache service opens the mysql service, opens the browser and enters http://localhost/test.php The password should be correct and there should be no information displayed. Fill in the wrong password Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@' localhost’ (using password: YES) in C:\httpd-2.4.34-win64-VC15\Apache24\htdocs\test.php on line 1 can not connet The…

How does php convert an array to an xml string-PHP problem

How to convert an array to an xml string in php: first create a PHP sample file; then use the “public function array2xml($arr, $level = 1) {…}” method to convert an array to A string of XML structure is sufficient. Recommendation: “PHP Video Tutorial” PHP converts an array into a string of XML structure The code is as follows: /** * Convert an array to an XML-structured string * @param array $arr the array to convert * @param int $level node level, 1 is Root. * @return string XML structure string */ public function array2xml($arr, $level = 1) { $s = $level == 1 ? “” : ''; foreach($arr as $tagname => $value) { if (is_numeric($tagname)) { $tagname = $value['TagName']; unset($value['TagName']); } if(!is_array($value)) { $s .= “”.(!is_numeric($value) ? '' : '').””; } else { $s .= “” . $this->array2xml($value, $level + 1).””; } } $s = preg_replace(“/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/”, ' ', $s); return $level == 1 ? $s.”” : $s; } The above is the detailed content of how PHP converts an array to an XML string. For more information, please pay attention to other related articles on 1024programmer.com!

How does js call php-PHP problem

The method of js calling php: first create a code sample file; then use the statement “” in js to realize the call. Recommendation: “PHP Video Tutorial” Example of JS Calling PHP and PHP Calling JS 1. Call the PHP file in JS mode and get the value in PHP Give a simple example to illustrate: For example, use the following sentence in the page test_json1 Call: There is such a piece of PHP code in test_json2.php: When the test_json1.php file is executed, the test_json2.php file will be called, and the output of the b.php file will be executed as a JS statement, So here will A prompt box pops up, the content is the value of the JS variable jstext, that is, the value assigned to jstext in the PHP file. Summary: In HTML, use JS to call the file to call the PHP file, then the PHP file The output will be used by the called page as JS code. 2. PHP calls the value in JS There is such a piece of code in the test_json3.php page: 3. PHP calls the method (function) in js Basically similar to the second case, use echo script to realize JS…

How to set phpmysql encoding – PHP problem

How to set php mysql encoding: 1. Execute the statement “SET NAMES 'utf8';” before sending the query; 2. Set the statement “character set utf8;” when creating the database; 3. Modify the field encoding to “utf8”. Recommendation: “PHP Video Tutorial” php+mysql set encoding format When we access the MySQL database through PHP, even if the default character set of the table is set to utf8, and the query is sent through UTF-8 encoding, you will find that the data stored in the database is still garbled. The problem lies in the connection layer. The solution is to execute the following sentence before sending the query: 1. SET NAMES 'utf8'; It is equivalent to the following three commands: SET character_set_client = utf8; SET character_set_results = utf8; SET character_set_cOnnection= utf8; 2. Create a database mysql> create database name character set utf8; 3. Create a table CREATE TABLE `type` ( `id` int(10) unsigned NOT NULL auto_increment, `flag_deleted` enum('Y','N') character set utf8 NOT NULL default 'N', `flag_type` int(5) NOT NULL default '0', `type_name` varchar(50) character set utf8 NOT NULL default '', PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8; 4. Modify the database to utf8. alter database name character set utf8; 5. Modify the table with utf8…

What are the php character conversion functions-PHP problem

PHP character conversion functions include: 1. addcslashes function; 2. addslashes function; 3. bin2hex function; 4. fprintf function; 5. hebrev function; 6. hex2bin function and so on. Recommendation: “PHP Video Tutorial” PHP character conversion functions are: addcslashes — escapes characters in a string with backslashes in C style addslashes — quotes strings with backslashes bin2hex — function converts a binary file containing data String to hexadecimal value chop — an alias for rtrim chr — returns the specified character chunk_split — splits a string into smaller chunks convert_cyr_string — Convert characters from one Cyrillic character to another convert_uudecode — Decode a uuencode encoded string convert_uuencode — Use uuencode to encode a string count_chars — returns information about the characters used in a string crc32 — computes the crc32 polynomial of a string crypt — one-way string hash echo — output one or more strings explode — split one string into another fprintf — write the formatted string into the stream get_html_translation_table — returns the translation table after using htmlspecialchars and htmlentities hebrev — converts logical-Hebrew to visual-order Hebrew (visual-Hebrew) hebrevc – converts logical-Hebrew to visual-Hebrew, and converts newlines hex2bin — Convert a hexadecimal string to a binary string html_entity_decode — Convert…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索