How to convert connected strings into character arrays in php
In PHP, you can use the str_split() function to convert a connected string into a character array. This function can split the string according to the specified length of the array element, split the string into substrings of the specified length, and pass them into the array one by one as array elements; you only need to set the second parameter of the function to 1 , or omit it to convert the continuous string into a character array, the syntax is "str_split(string,1)" or "str_split(string)".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer
Character array is used to store characters or strings. An element in the character array stores a character, which occupies one byte in memory. Example
#So in PHP, how to convert a continuous string into a character array?
In PHP, you can use the str_split() function to convert a continuous string into a character array.
str_split(string,length)
string: Required. Specifies the string to be split.
-
#length: Optional. Specifies the length of each array element. The default is 1.
If length is less than 1, the str_split() function will return FALSE. If length is greater than the length of the string, the entire string will be returned as the only element of the array.
str_split() function can split the string according to the specified length of the array element, split the string into substrings of the specified length, and pass them into the array one by one as an array element.
You only need to set the second parameter of the str_split() function to 1, or omit it to convert the continuous string into a character array.
Example: Convert the string "hello123" to a character array
<?php header("Content-type:text/html;charset=utf-8"); $str="hello123"; echo "原字符串:"; var_dump($str); echo "字符串转字符数组:"; $arr1=str_split($str,1); var_dump($arr1); $arr2=str_split($str); var_dump($arr2); ?>
It can be seen that regardless of whether the second parameter of the str_split() function is set to 1 , or you can omit it.
Extended knowledge: explode() function--convert a string into an array
explode($delimiter, $string [, $limit])The parameter description is as follows:
-
$delimiter: The delimiter character used to split the string;
- $string: The string that needs to be split;
- $limit: Optional parameter, can be empty, specifies the number of array elements to be returned;
-
If $limit is not empty and is a positive number, the returned array contains at most $limit elements, and the last element contains the remainder of $string;
- If $limit is not empty and is negative, all elements except the last $limit elements are returned;
- If $limit is 0, it will be treated as 1;
- If $limit is empty, all array elements are returned.
' '.
<?php header('content-type:text/html;charset=utf-8'); $str = 'hypertext language programming'; var_dump($str); $arr=explode(" ",$str); var_dump($arr); ?>
PHP Video Tutorial"
The above is the detailed content of How to convert connected strings into character arrays in php. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
