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 妈妈生日祝福语简短励志