Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はこのような文字列を持っています
$string = 'Name of product | 34';
これを2つの新しい文字列に分割したいと思います。
$productName = 'Name of product'; $productPrice = '34';
それを行うための最良の方法は何ですか?
list()これは、とを使用して非常に簡単に行うことができますexplode()。
list()
explode()
list($productName, $productPrice) = explode(" | ", $string);
$ productName string(15)"製品の名前" $ productPrice string(2) "34"
$newarray = explode(" | ", $string); echo $newarray[0]; //Name of product echo $newarray[1]; //34