查詢句子第一個單詞的 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, " ");
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP