Home >Backend Development >PHP Problem >How to remove double quotes from data obtained by php
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.
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('content-type:text/html;charset=utf-8'); $str = 'My name is "LiHua","20" years old!'; echo "原字符串:".$str."<br>"; $new = str_replace('"',"",$str); echo "新字符串:".$new; ?>
Method 2: Use the preg_replace() function With regular expressions/\"/
<?php header('content-type:text/html;charset=utf-8'); $str = 'My name is "LiHua","20" years old!'; echo "原字符串:".$str."<br>"; $new = preg_replace('/\"/',"",$str); echo "新字符串:".$new; ?>
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!