2017-04-10 186 views
1

我试图在While循环中过滤一些条目。这个我试图用strpos函数,不幸的是,当我使用变量作为针,我没有得到结果。用PHP匹配一个字符串到另一个字符串

无结果: $tra = strpos($HRreq, $entry_type)

结果:$tra = strpos($HRreq, "string");

但是,我需要它是在while循环变量。

$select_exec = odbc_exec($amos_db,$select_personnel); 
    while ($row = odbc_fetch_array($select_exec)){ 
     $username = $row['user_sign']; 
     $entry_type = $row['entry_type']; 
     $fullname1 = $row['lastname'] . $row['firstname']; 
     $fullname = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($fullname1)))))); 
     $userno = $row['employee_no_i']; 
     $tra = strpos($HRreq, "$entry_type"); 
     echo $entry_type ." = ". $tra; 
     } 

由于代码长度超过500行,我添加了部分代码。我希望这足以让我知道我想要完成什么

+1

你可以添加你使用的代码吗? –

+0

您确定变量不为空或空白吗? – Swellar

+0

我增加了更多的代码,我尝试''echo'$ entry_type',然后是'$ tra',它只返回'$ entry_type',但$ tra'上为null' – Wvs

回答

0

我发现数据库在变量后面带有空格返回。我加了一个trim(),问题解决了。这是一个愚蠢的错误。

相关问题