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

How to remove double quotes from data obtained by php

青灯夜游
Release: 2023-03-15 21:08:01
Original
3055 people have browsed it

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='获取的数据';
Copy after login

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

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

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!

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