【问题标题】:Check if string contains word (not a sentence string) [duplicate]检查字符串是否包含单词(不是句子字符串)[重复]
【发布时间】:2015-12-07 12:40:17
【问题描述】:

我正在编写一个 PhP 脚本,但对于过滤器,我需要在字符串中搜索字符串。
这是我目前拥有的脚本:

<?php
$stringtocheck = "Schiphol-Almere C./Hilversum/Utrecht C.";
$searchfor = "Hilversum";

// do the magic stuff over here
?>

如何让脚本在“$stringtocheck”中搜索“$searchfor”?

【问题讨论】:

标签: php string search


【解决方案1】:

使用strposhaystack 字符串中查找 needle 字符串。而这里 haystack 字符串是 stringtocheckneedle 字符串是 searchfor

函数使用示例:

<?php
$stringtocheck = "Schiphol-Almere C./Hilversum/Utrecht C.";
$searchfor = "Hilversum";

if(strpos($stringtocheck, $searchfor) !== false)
    echo true;
?>

【讨论】:

  • 我试过strpos,但是不行。
  • 哦,我打错了,现在好像可以用了
  • 它对你有用吗?
猜你喜欢
  • 1970-01-01
  • 2016-12-05
  • 2014-01-25
  • 1970-01-01
  • 1970-01-01
  • 2011-11-09
  • 2013-05-18
  • 2015-06-24
  • 1970-01-01
相关资源
最近更新 更多