如何将用逗号分隔的字符串转换为PHP中的双引号? [重复]
问题描述:
This question already has an answer here:
I have a string for example: apple,orange,melon,grape,peach
I want to take the items and display them like this: "apple","orange","melon","grape","peach"
What is the most optimized way to reach this goal?
</div>
此问题已经存在 这里有一个答案: p>
-
php implode(101),带引号
11 answers
span>
li>
- 如何在PHP中将逗号分隔的字符串拆分为数组? 6个答案\ r span> li> ul> div>
我有一个字符串,例如: apple,orange, 甜瓜,葡萄,桃子 p>
我想拿这些物品并像这样显示: “苹果”,“橙子”,“甜瓜”,“葡萄”,“桃子” \ n
实现这一目标的最佳方式是什么? p> div>
- 如何在PHP中将逗号分隔的字符串拆分为数组? 6个答案\ r span> li> ul> div>
答
$string = 'apple,orange,melon,grape,peach';
$string = explode(',', $string);
$string = '"' . implode('","', $string) . '"';
echo $string;
Compressed:
$string = 'apple,orange,melon,grape,peach';
echo '"' . implode('","', explode(',', $string)) . '"';