Home  >  Article  >  Backend Development  >  How to remove double quotes from data obtained by php

How to remove double quotes from data obtained by php

青灯夜游
青灯夜游Original
2022-04-27 14:58:183025browse

Removal method: 1. Use the "$str='obtained data';" statement to store the data as a string in a variable; 2. Use "str_replace('"',"",$str )" or "preg_replace('/\"/',"",$str)" statement can replace the double quotes of the string with empty characters.

How to remove double quotes from data obtained by php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Data obtained by php Method to remove double quotes

1. Store the obtained data as a string in a variable

$str='获取的数据';

2. Replace the double quotes of the string with empty characters

Method 1: Use the str_replace() function

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = &#39;My name is "LiHua","20" years old!&#39;;
echo "原字符串:".$str."<br>";
$new = str_replace(&#39;"&#39;,"",$str);
echo "新字符串:".$new;
?>

How to remove double quotes from data obtained by php

Method 2: Use the preg_replace() function With regular expressions/\"/

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str = &#39;My name is "LiHua","20" years old!&#39;;
echo "原字符串:".$str."<br>";
$new = preg_replace(&#39;/\"/&#39;,"",$str);
echo "新字符串:".$new;
?>

How to remove double quotes from data obtained by php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove double quotes from data obtained by php. 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