PHP Rookie (4) string

Source: Internet
Author: User

In PHP, strings can be represented in three ways:

1. Single quotation marks

2. Double quotes

The difference between single and double quotes is that the contents of the variable in the single quotation mark are output as normal character content, and the variables in the double quotation marks are replaced with the values of the variables to output.

$name = "Joedlut"; $str = ' name is $name ', $str 2 = "name is $name"; Echo $str 1; Name is $nameecho $STR 2; Name is Joedlut

3. Use the delimiter <<< delimiter to define large formatted text, that is, the formatting in the text is preserved, and the text does not need to use escape characters.

The format is as follows

<<<str

formatting text

Str

<?php $str = "Tomorrow's Technology Dictionary", Echo <<<strmark <font color= "#FF0099" > $str listing, for details, please pay attention to the programming dictionary network: Strmark;? >

Note: Annotations cannot appear in delimiters. The starting and ending delimiters must be identical. The variables in formatted text are similar to double quotes and are replaced with the contents of variables.

===================================================================================

How do I connect strings?

Use. Note that the plus sign is not

$str 1 = "Hello"; $str 2 = "World"; Echo $str 1. $str 2;//helloworld

===================================================================================

Manually escaping a string

Manual escape is required when characters such as "" are included in the string

Echo ' select * from user where name=\ ' PHP project development record \ ';


A string with a large amount of data can be escaped by escaping the function

    1. Addslashes ()

      To escape the ' "null character 0 by adding \ to the string

      String addslashes (String str)

$STR = "SELECT * from book where name= ' Java Development combat '"; $a = addslashes ($STR); Echo $a;

2.string stripslashes ($STR)

To restore a string by applying the Stripslashes () function

$b = stripslashes ($a); Echo $b;

Note: Before all data is inserted into the database, it is necessary to escape the data using Addslashes (), in a way that the special characters are not escaped when inserting the database with an error.

====================================================================================

Gets the length of the string

int strlen (string str);

Intercept string

String substr (string str,int start,int length);

Retrieves whether needle has occurred in haystack

String Strstr (string haystack,string needle);

Retrieving the number of occurrences of needle in haystack

String Substr_count (String haystack,string needle)



This article is from the "thick Product Thin Hair" blog, please make sure to keep this source http://joedlut.blog.51cto.com/6570198/1853812

PHP Rookie (4) 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.