很简单,我有一个文件,每一行都有这样的内容
OneTwoThreeFourFiveSixSeven OneTwoThreeFourFiveSixSeven OneThreeFourSevenFiveSix
OneThreeFourSevenFiveSix OneTwoThreeFourFiveSixSeven OneThreeFourSevenFiveSix
如何检查这两行中是否有"五"字?
我试过了:
strstr();
strrpos();
strpos();
和其他的,但没有任何东西能给我正在寻找的功能。php 中是否有一些内置方法,或者我是否必须尝试构建要寻找这个的函数?
好的,这是代码:
foreach ($results as $result) {
foreach ($lines as $line) {
if(strpos($line, '$this->' . $result) || strpos($line, '($this->' . $result)){
$i++;
}
}
if($i == 0 && $result !== "__construct"){
print_r($result);
}
}
试试这个代码:
strrpos — 查找子字符串在 字符串
如果未找到针,则返回 FALSE。
<?php
$str1 = "OneTwoThreeFourFiveSixSeven";
$str2 = "OneThreeFourSevenFiveSix";
if(strrpos($str1, "Two") !== FALSE){
echo 'Two is in $str1';
}else{
echo 'Two is not in $str1';
}
if(strrpos($str2, "Two") !== FALSE){
echo 'Two is in $str2';
}else{
echo 'Two is not in $str2';
}
?>
在代码板中测试:http://codepad.org/8KbwMq36