PHP程序查找句子的第一个单词
为了找到句子的第一个单词,PHP代码如下-
示例
<?php $my_string = 'Hi there, this is a sample statement'; echo "The first word of the string is ". strtok($my_string, " "); ?>
输出结果
The first word of the string is Hi
首先定义一个字符串-
$my_string = 'Hi there, this is a sample statement';
“strtok”函数是一个内置函数,用于将字符串分成指定数量的部分。在第一个空格出现之前,需要对字符串进行分割。此拆分字符串的第一部分在屏幕上显示为输出-
echo "The first word of the string is ". strtok($my_string, " ");
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短