2
当$ haystack =“my keyword”和$ needle =“my keyword”时,下面的测试返回false($ pos = 0),大概是因为我的stripos测试返回0,因为谷仓中没有空的空间。针在干草堆里,但谷仓门被堵塞了!
在这种情况下,我需要在比较中更改以返回true吗?
function my_test($post){
if($post->post_title == "") return false;
$haystack = my_esc2($post->post_title);
$needle = trim(my_getKeyword($post));
$pos = stripos($haystack, $needle);
if ($pos !== false) return true;
//returns 0 when $needle and $haystack are the same exact phrase. but should return 1
}
function my_getKeyword($post)
{
$myKeyword = get_post_meta($post->ID, '_my_keyword', true);
if($myKeyword == "") $myKeyword = $post->post_title;
$myKeyword = my_esc($myKeyword);
return " ".$myKeyword;
}
function my_esc($str, $quotation='"') {
if ($quotation != '"' && $quotation != "'") return false;
return str_replace($quotation, $quotation.$quotation, $str);
}
function my_esc2($str, $quotation='"') {
if ($quotation != '"' && $quotation != "'") return false;
return str_replace($quotation, '', $str);
}
什么返回0? `stripos()`或`my_test()`? – BoltClock 2011-01-27 20:23:21
函数`my_esc`和`my_esc2`做了什么?特别是,该评论的功能输出是什么?以这种方式摆脱“`”`“是一个错误(改用`trim`) – fredley 2011-01-27 20:26:59