假设我有一个文本Hello Himanshu How are you, Hope all well
。
我已将其存储在变量$content
中,即$content= "Hello Himanshu How are you, Hope all well"
中。
我想将第一个单词存储在1个变量中,将第二个单词存储到第二个变量中并且将文本的其余部分存储到第三个变量中。
我在PHP中使用了爆炸函数将前两个存储在不同的变量中,但我不知道如何将其余字符串存储在单个变量中。
$arr=explode(' ',trim($content));
$word1=$arr[0];
$word2=$arr[1];
$rest_words=$arr[2];
期望输出:
$word1=";你好"
$word2=";Himanshu"
$rest_words=";你好吗,希望一切顺利;
您可以使用
$arr=explode(' ',trim($content),3);
检查PHP爆炸手册的limit
部分
$content= "Hello Himanshu How are you, Hope all well";
$arr=explode(' ',trim($content),3);
$word1=$arr[0];
$word2=$arr[1];
$rest_words=$arr[2];
echo $word1, "'n", $word2, "'n", $rest_words;