2017-08-27 74 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,这工作。谢谢很多.. :) –