Home > Backend Development > PHP Tutorial > PHP method to return all words in a string_PHP tutorial

PHP method to return all words in a string_PHP tutorial

WBOY
Release: 2016-07-13 10:04:28
Original
859 people have browsed it

php method to return all words in a string

This article mainly introduces the method of php to return all words in a string. An example is an analysis of php string regular matching and array The operation skills have certain reference value. Friends in need can refer to it

The example in this article describes how php returns all words in a string. Share it with everyone for your reference. The specific analysis is as follows:

This code returns all words in the string, removing duplicate elements when $distinct=true. The code is as follows:

?

1

2

3

4

5

6

7

8

9

10

function split_en_str($str,$distinct=true) {

preg_match_all('/([a-zA-Z]+)/',$str,$match);

if ($distinct == true) {

$match[1] = array_unique($match[1]);

}

sort($match[1]);

return $match[1];

}

?>

1 2

3

4 5

67 8 9 10
function split_en_str($str,$distinct=true) {

preg_match_all('/([a-zA-Z]+)/',$str,$match);
if ($distinct == true) {<🎜> <🎜>$match[1] = array_unique($match[1]);<🎜> <🎜>}<🎜> <🎜>sort($match[1]);<🎜> <🎜>return $match[1];<🎜> <🎜>}<🎜> <🎜>?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/965528.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/965528.htmlTechArticleHow php returns all words in a string This article mainly introduces how php returns all words in a string , the example analyzes the skills of PHP string regular matching and array operations, with...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template