最も簡単な方法ですが、 strstr() で " の出現を見つけ、その後 substr() を使用して文字列を切り取ることが最善ではありませんでした。
$string = 'Your long text "with quotation"';
$occur = strpos($string, '"'); // the frst occurence of "
$occur2 = strpos($string, '"', $occur + 1); // second occurence of "
$start = $occur; // the start for cut text
$lenght = $occur2 - $occur + 1; // lenght of all quoted text for cut
$res = substr($string, $start, $lenght); // Your quoted text here ex: "with quotation"
そして、これを複数の引用テキストのループに挿入することができます:
$string = 'Your long text "with quotation" Another long text "and text with quotation"';
$occur2 = 0; // for doing the first search from begin
$resString = ''; // if you wont string and not array
$res = array();
$end = strripos($string, '"'); // find the last occurence for exit loop
while(true){
$occur = strpos($string, '"', $occur2); // after $occur2 change his value for find next occur
$occur2 = strpos($string, '"', $occur + 1);
$start = $occur;
$lenght = $occur2 - $occur + 1;
$res[] = substr($string, $start, $lenght); // $res may be array
$resString .= substr($string, $start, $lenght); // or string with concat
if($end == $occur2)
break; // brak if is the last occurence
$occur2++; // increment for search next
}
echo $resString .'<br>';
exit(print_r($res));
結果:
"with quotation""and text with quotation"
or
Array ( [0] => "with quotation" [1] => "and text with quotation" )
正規表現を使用しない簡単な方法です。誰かを助けてください:)(下手な英語でごめんなさい)