Home  >  Article  >  Backend Development  >  How to remove double quotes from a string in php using regular expressions

How to remove double quotes from a string in php using regular expressions

WBOY
WBOYOriginal
2022-02-10 17:17:382963browse

In PHP, you can use the "preg_replace" function and the "/(\")/" regular expression to remove double quotes from a string. This function is used to perform a regular expression search and replacement. The syntax is "preg_replace('/(\")/', '', string)".

How to remove double quotes from a string in php using regular expressions

The operating environment of this tutorial: Windows 10 system, PHP version 7.1, DELL G3 computer

How to use regex to remove double quotes from a string in php

preg_replace function performs a regular expression search and replace.

Syntax

mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )

Search for the part of subject that matches pattern and replace it with replacement.

Parameter description:

  • $pattern: The pattern to be searched can be a string or a string array.

  • $replacement: String or string array used for replacement.

  • $subject: The target string or string array to be searched and replaced.

  • $limit: Optional, the maximum number of substitutions for each subject string for each pattern. The default is -1 (no limit).

  • #$count: Optional, the number of times the replacement is performed.

Return value

If subject is an array, preg_replace() returns an array, otherwise it returns a string.

If a match is found, the replaced subject is returned, otherwise the unchanged subject is returned. If an error occurs, NULL is returned.

First we need to write a regular pattern that matches double quotes. You must understand that double quotes are a special character. According to the regular rules, special characters need to be escaped, so we get the regular pattern $reg='/(\") /';

The example is as follows:

Output result:

How to remove double quotes from a string in php using regular expressions

##Recommended learning: "

PHP Video Tutorial

The above is the detailed content of How to remove double quotes from a string in php using regular expressions. 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