Home >Backend Development >PHP Problem >PHP learning: in-depth understanding of strings

PHP learning: in-depth understanding of strings

慕斯
慕斯Original
2021-05-26 11:43:331677browse

The previous article introduced to you "How should we use multiple nesting of if statements in PHP process control? ? ? 》, this article continues to introduce you to strings in PHP:

PHP learning: in-depth understanding of strings

In the previous articles, we also mentioned related issues such as strings in PHP , in the next few days we will continue to explain in depth some other issues about strings: First, we will divide it into three parts to learn about PHP strings from the beginning:

  • Introduction to strings

  • Use of string

  • Use of string function library

1: PHP string Introduction

  • String is one of the important data types in PHP and is one of the scalar types;

  • A string is a series of characters, each character is a byte;

  • The string needs to be defined in single quotes, double quotes, and delimiters

(single quotes) The code demonstration is as follows:

<?php
/*字符串定义在单引号中的使用
*/
echo &#39;人生十有八九不如意&#39;; 
//在单引号引起来的字符串中不能再包含引号
//否则会报错。
//在单引号中如果在包含单引号需要使用转义字符&#39;\&#39;转义
?>

The demonstration results are as follows:

PHP learning: in-depth understanding of strings

(Double quotes) The code demonstration is as follows:

<?php
$poem = &#39;落花人独立,微雨燕双飞&#39;;
echo "$poem";//双引号可以解析变量,而单引号没有解析变量的作用
echo "<hr>";
echo "落花人独立,微雨燕双飞,{$poem}";
//可以用花括号{}括一个变量,就可以将变量分离出来解析,{}两边不要有空格
?>

The demonstration results are as follows:

PHP learning: in-depth understanding of strings

Recommended learning: "PHP Video Tutorial

The above is the detailed content of PHP learning: in-depth understanding of strings. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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