2017-08-27 82 views
0

我試圖引爆多個字符串像這樣多個字符串:如何爆炸引號

$str1 = 'Apple\'s OS and the "Microsoft OS", ----- any text with quotes & symbols ---- '; 
$str2 = 'Sony\'s Laptop and the "Toshiba\'s"'; 

$string = "".$str1.",".$str2.""; 
$result = explode(',',$string); 

echo "Str1 : ".$result[0]."<br/>"; 
echo "Str2 : ".$result[1]."<br/>"; 

但我發現了這樣的輸出:

Str1 : Apple's OS and the "Microsoft OS" 
Str2 : ----- any text with quotes & symbols ---- //This Str2 actually is the part of Str1 

我想這個輸出 - >

`Str1 : Apple's OS and the "Microsoft OS, ----- any text with quotes & symbols ---- 
Str2 : Sony's Laptop and the "Toshiba's"` 

請幫忙。

+3

你的代碼是做什麼它應該的功能。你應該展示你的期望。也許你不應該使用爆炸功能。 –

+1

如果您正在尋找$ str2。嘗試'結束($結果)'。或者遍歷整個數組。 – jh1711

+0

是的,你應該知道在這種情況下有一個'$ result [3]' –

回答

1

下面是這是否

function implodeStrings(...$array) { 
    $output = []; 

    foreach($array as $str) { 
     $output[] = $str; 
    } 

    return $output; 
} 

You can find a working example here.

+0

謝謝Jarzon,這工作。謝謝很多.. :) –