Home > Article > Backend Development > How to remove quotes before and after a string in php
The way PHP removes the quotes before and after a string is: you can first use the preg_match() function to determine whether the string starts and ends with quotes, and then use the substr() function and strlen() function to extract the quotes. The string can be.
To remove the quotes before and after the string, you can use the preg_match() function to determine whether the string starts and ends with quotes, and then use the substr() function with The strlen() function gets the string content in quotes and puts it into a new array.
(Recommended learning: php tutorial)
Related function introduction:
substr() function returns part of the string.
Syntax:
substr(string,start,length)
Return value:
Returns the extracted part of the string, returns FALSE if it fails, or returns an empty string.
Code implementation:
function remove_quote(&$str) { if (preg_match("/^\"/",$str)){ $str = substr($str, 1, strlen($str) - 1); } //判断字符串是否以'"'结束 if (preg_match("/\"$/",$str)){ $str = substr($str, 0, strlen($str) - 1);; } return $str; }
The above is the detailed content of How to remove quotes before and after a string in php. For more information, please follow other related articles on the PHP Chinese website!