Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP,使用preg_replace删除双引号内的字符串?_Php_Preg Replace - Fatal编程技术网

PHP,使用preg_replace删除双引号内的字符串?

PHP,使用preg_replace删除双引号内的字符串?,php,preg-replace,Php,Preg Replace,我有一个以下格式的PHP字符串: $str = 'This is a "sample string"'; 我想删除双引号字符串。像这样: This is a 我尝试的是: $fileread = preg_replace('!/\*.*?\*/!s',' -', $fileread); $fileread = preg_replace('![ \t]*//.*[ \t]*[\r\n]!', '', $fileread); $separator = preg_replace('/"[^"]+"

我有一个以下格式的PHP字符串:

$str = 'This is a "sample string"';
我想删除双引号字符串。像这样:

This is a
我尝试的是:

$fileread = preg_replace('!/\*.*?\*/!s',' -', $fileread);
$fileread = preg_replace('![ \t]*//.*[ \t]*[\r\n]!', '', $fileread);
$separator = preg_replace('/"[^"]+"/','',$fileread);
$separator = explode(" ",$separator);
有没有更简单的方法提取它?


<?php
    $str = 'This is a "sample string".';
    $str = preg_replace('#(").*?(")#', '', $str);
    echo $str;
?>

您只需匹配双引号中包含的字符串,并将其替换为空字符串即可:

$str = 'This is a "sample string".';

$str = preg_replace('/".*"/', '', $str);

echo $str;

您可以简单地匹配双引号中包含的字符串,并将其替换为空字符串:

$str = 'This is a "sample string".';

$str = preg_replace('/".*"/', '', $str);

echo $str;
使用以下命令:-

$fileread=preg_replace(“+[a-z a-z 0-9!@$%^&*()]+”,“”, $fileread)

使用以下命令:-

$fileread=preg_replace(“+[a-z a-z 0-9!@$%^&*()]+”,“”, $fileread)


这就是我要找的。谢谢兄弟!这就是我要找的。谢谢兄弟!