去除方法:1、用“$str='获取的数据';”语句将数据作为字符串存入一个变量中;2、用“str_replace('"',"",$str)”或“preg_replace('/\"/',"",$str)”语句将字符串的双引号替换为空字符即可。
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
php获取的数据去除双引号的方法
1、将获取的数据作为字符串存入一个变量中
$str='获取的数据';
2、将字符串的双引号替换为空字符
方法1:利用str_replace()函数
<?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;
?>
方法2:利用preg_replace()函数配合正则表达式/\"/
<?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;
?>