duansha8764
2017-04-28 03:41
浏览 94
已采纳

如何将用逗号分隔的字符串转换为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>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxie2029 2017-04-28 03:46
    已采纳
    $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)) . '"';
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题