How to remove quotes before and after a string in php

王林
Release: 2023-03-02 14:04:01
Original
4429 people have browsed it

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.

How to remove quotes before and after a string in php

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)
Copy after login

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;
  }
Copy after login

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!

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!