Summary of php string usage. For more information about php strings, see. 1. Evaluate the length, the most basic
$ Text = "sunny day ";
$ Count = strlen ($ text); // $ count = 9
2 string truncation Number of characters before truncation
$ Article = "breaking news: In ultimate irony, man bites dog."; $ summary = substr_replace ($ article, "...", 40 );
3 count words
$ Article = "breaking news: In ultimate irony, man bites dog."; $ wordCount = str_word_count ($ article );
// $ WordCount = 8
4. convert a string into an HTML connection $ Url = "W. J. Gilmore, LLC (http://www.jb51.net )";
$ Url = preg_replace ("/http: // ([A-z0-9 ../-] +)/", "$0", $ url );
5 Remove the HTML string from the character $ Text = strip_tags ($ input ,"
");
6 nl2br:
$ Comment = nl2br ($ comment );
Changed to HTML format
7 Wordwrap
Limit the number of words per line
$ Speech = "Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. ";
Echo wordwrap ($ speech, 30 );
Output:
Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service