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, " ");
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短