I used exec() to pull out the man pages with the following code:
$oares = array();
exec("man ar", $oares);
foreach ($oares as $kk => $vv) {
// $oares contain lines of output from `man ar`
// d() is a custom function from https://kint-php.github.io/kint/, similar to var_dump();
d($vv);
d("NAME");
d(trim($vv) == "NAME");
d($vv == "NAME");
d("NAME" == "NAME");
d(mb_strpos(trim($vv), "NAME"));
}
For one of the iterations of this foreach loop, where $vv = "NAME" (which is a line of output from man ar
), the comparisons do not match as they should:
┌─────────────────────────────────────────────────────────────┐
│ $vv │
└─────────────────────────────────────────────────────────────┘
UTF-8 string (12) "NAME"
┌─────────────────────────────────────────────────────────────┐
│ literal │
└─────────────────────────────────────────────────────────────┘
string (4) "NAME"
┌─────────────────────────────────────────────────────────────┐
│ trim($vv) │
└─────────────────────────────────────────────────────────────┘
UTF-8 string (12) "NAME"
┌─────────────────────────────────────────────────────────────┐
│ trim($vv)=="NAME" │
└─────────────────────────────────────────────────────────────┘
boolean false
┌─────────────────────────────────────────────────────────────┐
│ $vv=="NAME" │
└─────────────────────────────────────────────────────────────┘
boolean false
┌─────────────────────────────────────────────────────────────┐
│ "NAME"=="NAME │
└─────────────────────────────────────────────────────────────┘
boolean true
mb_strpos(trim($vv), "NAME") - also return false
I think it should be because $vv contains a UTF-8 string, while the "NAME" literal is not a UTF-8 string. What do I have to do so that the comparisons and the use of the mb_strpos function will all return true?