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 官宣新年祝福语简短