2017-04-10 180 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(),問題解決了。這是一個愚蠢的錯誤。

相關問題