如何用引号分解多个字符串

时间:2017-08-27 23:20:58

标签: php string

我试图像这样爆炸多个字符串:

$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 

我想要这个输出 - &gt;

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

请帮忙。

1 个答案:

答案 0 :(得分:1)

这是一个能够做到这一点的功能

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

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

    return $output;
}

You can find a working example here.