How to intercept strings by words in php, intercept strings in php_PHP tutorial

WBOY
Release: 2016-07-13 09:57:39
Original
895 people have browsed it

How to intercept strings by words in php, how to intercept strings by words in php

The example in this article describes the method of intercepting strings by words in php. Share it with everyone for your reference. The specific analysis is as follows:

Specify the number of strings and words here to intercept
Copy code The code is as follows: function limit_words($string, $word_limit)
{
$words = explode(" ",$string);
Return implode(" ",array_splice($words,0,$word_limit));
}
//Example Usage
$content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. echo limit_words($content,20);
?>

I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/980222.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/980222.htmlTechArticleHow to intercept strings by words in php, how to intercept strings by words in php. This article describes the method of intercepting strings by words in php. method. Share it with everyone for your reference. The specific analysis is as follows: This refers to...
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