Reputation: 4995
I have a string that looks like this
$string = 'Name of product | 34';
I want to break it into two new strings that'll be this:
$productName = 'Name of product';
$productPrice = '34';
What is the best way to do that?
Upvotes: 0
Views: 932
Reputation: 2343
$newarray = explode(" | ", $string);
echo $newarray[0]; //Name of product
echo $newarray[1]; //34
Upvotes: 4
Reputation:
You can do this quite simply using list()
and explode()
:
list($productName, $productPrice) = explode(" | ", $string);
$productName string(15) "Name of product" $productPrice string(2) "34"
Upvotes: 5