In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the method of escaping strings in PHP". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Escape character-manually escape string
In the previous article, we introduced escape characters, which can be thought of as special characters that can be escaped. Escape characters usually start with a backslash "\", followed by one or more characters. In this way, the escape character has a meaning that can be escaped. Simply put, escape characters are treated as a special character constant.
Escape characters can convert ordinary characters into special uses, and with these special purposes, characters can be transformed into their original meaning.
If you want to use escape characters to convert a string, it should be noted that if a string is defined in single or double quotes, if there are characters in the string that can interfere with the definition of the string, at this time, we need to escape the characters that may have interference in the string, so that we can avoid ambiguity in the definition of conceit.
Next, let's take a look at escaping a string by escaping characters through an example, as follows:
When we want to output: URL: 'https://www.yisu.com/', if we simply use echo to output a string, the characters in it may affect the final output and cause errors. This problem can be avoided by escaping characters:
Output result:
At this point, we escape the string through escape characters, so that we can output the results we want.
This kind of manual escape is suitable for some simple strings, when the string is very complex, or the string is very long, it is troublesome to use escape characters for manual escape, is there any good solution?
The addslashes () function and the stripslashes () function are provided in PHP to automatically escape strings, so let's take a look.
Addslashes () function-automatically escapes strings
The addslashes () function provided in PHP is used for automatic escape. Through the addslashes () function, you can append a backslash "\" before a predefined character in a string, where the predefined character includes single quotation marks, double quotes, and backslash.
The basic syntax format of this function is as follows:
Addslashes (string)
It is important to note that the parameter string represents the string that needs to be escaped, and the result returned is the string that has been escaped.
Let's take a look at the use of this function through an example, as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.