php:查找字符串

来源:互联网 发布:nginx配置域名 编辑:程序博客网 时间:2024/06/05 03:59

查找字符串

如果有一个字符串$str = 'I want to study at imooc';,怎么样找到其中的imooc在哪个位置呢?

查找字符串,我们需要用到PHP的查找字符串函数strpos();

函数说明:strpos(要处理的字符串, 要定位的字符串, 定位的起始位置[可选])

例子:

$str = 'I want to study at imooc';$pos = strpos($str, 'imooc');echo $pos;//结果显示19,表示从位置0开始,imooc在第19个位置开始出现

任务

$str = 'What is your name?',找一下name所在的位置。

<?php//查找字符串$str = 'What is your name?';$str = strpos($str,'name');echo $str;?>


0 0