PHP String Usage Summary _php Tutorial

Source: Internet
Author: User
1 Seeking length, the most basic
$text = "Sunny Day";
$count = strlen ($text); $count = 9


2 string interception
The number of characters before interception
$article = "Breaking news:in ultimate irony, man bites dog."; $summary = Substr_replace ($article, "...", 40);

3 Count The number of words
$article = "Breaking news:in ultimate irony, man bites dog."; $wordCount = Str_word_count ($article);
$wordCount = 8

4 Connect a string into HTML
$url = "W.J. Gilmore, LLC (http://www.jb51.net)";
$url = Preg_replace ("/http://([a-z0-9./-]+)/", "$", $url);

5 Removing HTML strings from characters
$text = Strip_tags ($input, "
");

6 NL2BR:
$comment = NL2BR ($comment);
into HTML format

7 WordWrap
Limit the number of words per line
$speech = "Four score and seven years ago we fathers brought forth, upon this continent, a new nation, conceived in Liber Ty, and dedicated to the proposition, all men is created equal. ";
Echo WordWrap ($speech, 30);

Output:
Four score and seven years ago we fathers brought forth, upon this continent, a new nation, conceived in Liberty, and ded Icated to the proposition, all men is created equal.

http://www.bkjia.com/PHPjc/321986.html www.bkjia.com true http://www.bkjia.com/PHPjc/321986.html techarticle 1 for length, the most basic $text = "Sunny Day"; $count = strlen ($text);//$count = 9 2 string intercept the number of characters before interception $article = "Breaking news:in u Ltimate irony, man b ...

  • Contact Us

    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

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.