Strange PHP string compare effect, could this be made nicer? -
i've updated website , found annoying problem in pages resolved it, i'm not realy convinced should this. me i'm not php expert unusual behaviour explain me whats going on.
i had code:
if($menu == "index"){ {if ($language == "uk"){echo "<td><h1>welcome</h1>";} {if ($language == "nl"){echo "<td><h1>welkom </h1>";} } else // if $menu not index displayed hyperlink welcome page
the string thing here while checking language worked fine. comparing $menu did not work, if contained word index whole page generated on fly , string operations done before assumed maybe, despite tested with
echo "dump menu variable " . $menu
which resulted in jut displaying word index on page. maybe there go wrong in string types or that
so experimented with
if($menu === "index")
no luck
well solved
if (strpos($menu,'index' !==false)
is way should done???, don't sense comfortable it. me unusual $language works should (in opinion). there type problem here, or maybe unwanted endings \n perhaps ehm normalize string content of readable string comparions or, different type of equal operator. feels me $menu handled more easily. maybe reformat or i'm not sure here.
looks indeed index-string containing whitespaces, instead of strpos utilize trim( $menu )
rid of them.
but best prevent occurence. seek echo "dump menu variable |" . $menu ."|";
or var_dump( $menu )
identify additional characters.
maybe post, code-segment $menu filled.
(sorry can't comment)
php string compare
No comments:
Post a Comment