Reputation: 1
"This is a sentence, which is, weirdly seperated, by commas."
How can I delete the sentence between the 2nd comma and the third to get this sentence in PHP:
"This is a sentence, which is .... by commas."
Upvotes: 0
Views: 121
Reputation: 923
$sentence= "This is a sentence, which is, weirdly separated, by commas.";
$pieces = explode(",", $sentence);
echo $pieces[0] .', '. $pieces[1].', ...';
The explode function allows you to make an array of the string and separate each entry by what you put in quotes, in this case, a comma.
The last line concatenates the pieces of the array you want, leaving out the third section aka pieces[2].
Upvotes: 2