如何在PHP中获得句子的第一个单词? [英] How to get the first word of a sentence in PHP?
本文介绍了如何在PHP中获得句子的第一个单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从字符串中提取变量的第一个单词.例如,输入以下内容:
I want to extract the first word of a variable from a string. For example, take this input:
<?php $myvalue = 'Test me more'; ?>
结果输出应为Test
,这是输入的第一个字.
我该怎么办?
The resultant output should be Test
, which is the first word of the input.
How can I do this?
推荐答案
您可以使用爆炸功能如下:
$myvalue = 'Test me more';
$arr = explode(' ',trim($myvalue));
echo $arr[0]; // will print Test
这篇关于如何在PHP中获得句子的第一个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文