2016-10-17 8 views
0

は、私は、次の形式のPHPの文字列を持っている:PHP、preg_replaceを使用して二重引用符で囲んだ文字列を削除しますか?

$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); 

それを抽出するための簡単な方法はありますか?

答えて

3

あなたは、単に二重引用符の内側に含まれる文字列と一致し、空の文字列に置き換えることができます。

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

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

echo $str; 
+0

これは私が探しているものです。ありがとう兄貴!感謝! –

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

ありがとう!あなたは私をそこに救った。 –

1

は、この使用します。 - ( '(

$ FILEREAD =にpreg_replaceを"+ [az AZ 0-9!@#$%^ & *()] +") '、 ""、 $ fileread);

+0

ありがとう!しかしもう一つの方法。 –

関連する問題