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.
“这是一个句子,奇怪地用逗号分隔。”
如何删除第二个逗号和第三个逗号之间的句子以在 PHP 中获取此句子:
“这是一个句子,它是……用逗号。”
$sentence= "This is a sentence, which is, weirdly separated, by commas."; $pieces = explode(",", $sentence); echo $pieces[0] .', '. $pieces[1].', ...';
explode 函数允许您创建一个字符串数组,并用引号中的内容分隔每个条目,在本例中为逗号。
最后一行连接了您想要的数组片段,省略了第三部分,即片段 [2]。