0
if文を実行するためにいくつかの文字列を比較しようとしています。私はstr_replace
とtrim
を使用してすべての空白を削除する方法をいくつか試しましたが、複数の単語がある場合は機能しません。なにか提案を?ありがとう。PHPの文字列比較str_replaceが機能していない
文字列
//check company industry
$checkcompanyq = "SELECT type,id,employee_id FROM company";
$checkcompanyresult = mysqli_query($db, $checkcompanyq);
$companyassoc = mysqli_fetch_assoc($checkcompanyresult);
$companyindustry = $companyassoc['type'];
$comindustrynospace = str_replace(' ','',$companyindustry);
それは一つの単語だとき、それは動作します。この文字列は動作し、if文が実行されます
if($comindustrynospace=="Insurance"){
//do something
}
複数の単語があると動作しません。この文字列は文句を言わない仕事とif文文句を言わない、私はトリムと試みたが、実行しません
if($comindustrynospace=="RealEstate&Rental"){
//do something
}
実行のいずれか
if(trim($comindustrynospace)==trim("RealEstate&Rental")){
//do something
}
これは$ companyindustryがstr_replace
$companyindustry = 'Real Estate & Rental';
てみ[この](http://php.net/manual/en/function.stristr.php) – hungrykoala
あなたの全体 '$のcompanyindustry'列過去できますか? –
str_replaceが正常に動作しています** $ comindustrynospace ** var –