php - split sentence with variable number of words (separated by blank spaces) into words and then build sentence with & as delimiter -
For example, in one case there can be 2 words in the sentence, and in the second case the sentence can have 5 words. I think that I can use the explosion to get every word (something like) in every case, the problem is that after the initial problem that the number of words in each sentence varies, I should like the sentences, but & Amp; Instead of the empty space, e.g.,
Input: This sentence is output: this & amp; Is & amp; A & amp; Sentence
I'm new to php, so please bear with me if this question is very simple.
Thanks in advance for any indication!
Use -
$ sentence = "This is a sentence "; $ Word = explosion ('', $ sentence); Print_r (word $);
and then -
$ updated = intestine ("& amp;", $ word); Resonance $ update;
This method does not care how many words in the sentence are, so it can be used with a sentence.