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 口才课期末祝福语简短
13 回国了祝福语简短英语
14 中考祝福语简短古风短句
15 广西考试祝福语朋友简短
16 中式蛋糕开业祝福语简短
17 喜欢新车的祝福语简短
18 田婆婆生日祝福语简短