Introduction to the concept of PHP strings

伊谢尔伦
Release: 2023-03-07 11:52:01
Original
1770 people have browsed it

String refers to a set of zero or more characters. Because PHP has been developed for web since its inception.

Because in website development, string processing is a highlight of PHP. In php, 1 is a string, 2 is an arrayfunction, there are many of them and they are very easy to use.

Simply put, strings are what we say every day. For example, I want to say "I want to learn PHP language development" or "I want to create a good website" and so on. It's all the characters I want to express that people can see. Generally visible text, HTML tags, special characters, English, etc., can all be considered strings.

The characters mentioned here mainly include the following types:

1. Number type , such as 1, 11, 111, etc.

2. Letter type, such as a, df, msn, etc.

3. Special types, such as #, $, ^, &, etc.

4. Invisible characters, such as \n (line feed character), \r (carriage return character), \t (Tab character), etc.

Invisible characters are a special group of characters used to control string formatted output. They are invisible in the browser. Generally, only string output can be seen. result.

The following is a simple example of a string:

<?php
    echo "goods  \r  apple  \n sony";      //输出字符串
?>
Copy after login

The output result is:

goods      apple
 sony
Copy after login

Tips: The result of running the example in the browser is, "goods apple sony" , you need to click the "right mouse button" in the browser / select "View web page source code" to view the output of the string.

Picture similar to the following:

Introduction to the concept of PHP strings

How to convert a value into a string?

#A value can be converted to a string by preceding it with (string) or using the strval() function. In an expression that expects a string, it is automatically converted to string. This conversion occurs, for example, when using the functions echo or print, or when comparing a variable to a string. Types and type conversions can be better explained below. You can also refer to the function settype().

A boolean value of TRUE is converted into a string of "1". Boolean FALSE is converted to "" (empty string). This conversion can be done between boolean and string.

An integer or float is converted to a numeric literal-style string (including the exponent part of the float). Floating point numbers using exponential notation (4.1E+6) can also be converted.

What needs to be noted here is: NULL is always converted into an empty string.

The above is the detailed content of Introduction to the concept of PHP strings. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!