PHP Learning String

Source: Internet
Author: User

1. String variables are used to store and process text;

2. The string variable is used to contain the value of the character, after creating the string, you can manipulate it, you can use the string directly in the function, or store it in a variable;

<?php

$txt = "Hello World"; When you assign a text value to a variable, remember the text value plus single or double quotation marks

Echo $txt;

?>

2. Functions and operators for manipulating strings:

(1) PHP's collocated operator: in PHP, there is only one string operator: the collocated operator (.), which is used to concatenate two string values together:

<?php

$txt 1= "Hello World";

$txt 2= "What a nice day!";

echo $txt 1. " ". $txt 2;

?>

(2) PHP strlen () function: strlen function returns the length of the string (number of characters)

<?php

Echo strlen ("Hello world!"); Strlen () is often used in loops and other functions because it is important to determine when the string ends;

?>

(3) PHP Strpos () function: the Strpos () function is used to find a string or a specified text within a string;

If a match is found in the string, the function returns the first matching character position and returns False if no match is found;

<?php

Echo Strpos ("Hello world!", "World"); The position of "world" is 6, not 7, because the first position of the string is 0, not 1

?>

PHP Learning String

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.