In PHP, string operation is one of the very common operations. In PHP 7.0 and above, string manipulation has been greatly improved. In this article, we will explore how to perform string manipulation in PHP 7.0.
- String length
In PHP 7.0, the way to get the string length is very simple, just use the strlen function. For example:
$string = "hello world"; $length = strlen($string); echo $length; // 输出 11
- String interception
In PHP 7.0, the method of string interception is also very simple. Use the substr function to easily intercept a string of specified length. For example:
$string = "hello world"; $substring = substr($string, 0, 5); echo $substring; // 输出 "hello"
In the above code, the first parameter of the substr function is the string to be intercepted, the second parameter is the starting number to intercept, and the third parameter is the length of interception.
- String concatenation
String concatenation in PHP 7.0 is the same as in previous versions. Use the dot (.) to concatenate strings. For example:
$hello = "hello"; $world = "world"; $string = $hello . " " . $world; echo $string; // 输出 "hello world"
- String replacement
In PHP 7.0, string replacement is very convenient. Just use the str_replace function. For example:
$string = "hello world"; $strReplaced = str_replace("world", "php", $string); echo $strReplaced; // 输出 "hello php"
In the above code, the first parameter of the str_replace function is the string to be replaced, the second parameter is the string to be replaced, and the third parameter is the string in which to perform the replacement. replace.
- String splitting
In PHP 7.0, the method of string splitting is very simple. Just use the explode function. For example:
$string = "hello,world,php"; $array = explode(",", $string); print_r($array); // 输出 Array([0] => hello[1] => world[2] => php)
In the above code, the first parameter of the explode function is the character used to split it, and the second parameter is the string to be split. After the split is completed, the explode function will return the split string in an array.
Summary:
In PHP 7.0, string operations are very convenient. We can use the strlen function to obtain the string length, the substr function to intercept the string, the period (.) to connect the strings, the str_replace function to replace the string, and the explode function to split the string. For string operations, we can also use other methods such as regular expressions.
The above is the detailed content of How to perform string operations in PHP7.0?. 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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools