如何判断单词helloword是否在一字符串中

peterpansh 2006-11-22 10:06:18
如何判断单词helloword是否在一字符串中
...全文
287 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
li1229363 2006-11-23
  • 打赏
  • 举报
回复
OK,问题解决了~LZ给分~顺便给偶+上点~大家一起升~
kenesyu 2006-11-23
  • 打赏
  • 举报
回复
学习~
chenjinaban 2006-11-22
  • 打赏
  • 举报
回复
strpos
Find position of first occurrence of a string (PHP 3, PHP 4, PHP 5)

int strpos ( string haystack, mixed needle [, int offset] )

Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used.

If needle is not found, strpos() will return boolean FALSE.

警告:
本函数可能返回布尔值 FALSE,但也可能返回一个与 FALSE 等值的非布尔值,例如 0 或者 ""。请参阅布尔类型章节以获取更多信息。应使用 === 运算符来测试本函数的返回值。

手册里有的啊
aruhan 2006-11-22
  • 打赏
  • 举报
回复
strpos
Find position of first occurrence of a string (PHP 3, PHP 4, PHP 5)

int strpos ( string haystack, mixed needle [, int offset] )

Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used.

If needle is not found, strpos() will return boolean FALSE.

警告:
本函数可能返回布尔值 FALSE,但也可能返回一个与 FALSE 等值的非布尔值,例如 0 或者 ""。请参阅布尔类型章节以获取更多信息。应使用 === 运算符来测试本函数的返回值。

手册里有的啊
lostgdi731 2006-11-22
  • 打赏
  • 举报
回复
grep
iasky 2006-11-22
  • 打赏
  • 举报
回复
<?php
if (strpos('fsdf fsdfa helloword agfasd', 'helloword') === false)
{
echo 'No!';
}
else
{
echo 'Find!';
}
?>
懒得去死 2006-11-22
  • 打赏
  • 举报
回复
strpos
zeroleonhart 2006-11-22
  • 打赏
  • 举报
回复
上面的strpos适用于不考虑helloword前后字符的情况.,比如,如果是thelloword, 一样会找出来

如果是需要helloword作为一个单独的单词出现,
可以用
preg_match('/\bhelloword\b/',$str)


-----------------------------------------------

strpos('fsdf fsdfa helloword agfasd', ' helloword ')
helloyou0 2006-11-22
  • 打赏
  • 举报
回复
上面的strpos适用于不考虑helloword前后字符的情况.,比如,如果是thelloword, 一样会找出来

如果是需要helloword作为一个单独的单词出现,
可以用
preg_match('/\bhelloword\b/',$str)

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧