By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,373 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,373 IT Pros & Developers. It's quick & easy.

String comparison problems

P: n/a
My website is based on some CMS sytem. From there I am getting a string
value passed into php, which I would like to compare to two possible
choices. The result of this comparison would be used to set a dropdown
menus selected option. For some reason I cannot do this right. I think
it might have something to do with foreign characters that I am using,
althogh I am not 100% sure...

Here is what I have.

$localvar = array("{string variable from CMS}"); // this comes
from the CMS and is either "kereskedő" or "magánszemély"
$choices = array("kereskedő", "magánszemély"); // this is just a
preset array with the two possibilities

echo '<select name="yourtype">'; // setting up
the pulldown menu
foreach ($choices as $value) {
echo "<option value=\"" . $value . "\"";
if ( $value === $localvar[0] ) echo " selected";
echo ">" . $value . "</options>";
}
echo '</select><br />';
If I echo $localvar[1] out I do get either 'kereskedő" or
"magánszemély", but when it passed through the conditional, it always
fails. What could be going on here?
Thanks in advance!

dombi

Jul 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 2006-06-30 18:30:16 -0700, dombi <do***@cox.net> said:
My website is based on some CMS sytem. From there I am getting a string
value passed into php, which I would like to compare to two possible
choices. The result of this comparison would be used to set a dropdown
menus selected option. For some reason I cannot do this right. I think
it might have something to do with foreign characters that I am using,
althogh I am not 100% sure...

Here is what I have.

$localvar = array("{string variable from CMS}"); // this comes
from the CMS and is either "kereskedő" or "magánszemély"
$choices = array("kereskedő", "magánszemély"); // this is just a
preset array with the two possibilities

echo '<select name="yourtype">'; // setting up
the pulldown menu
foreach ($choices as $value) {
echo "<option value=\"" . $value . "\"";
if ( $value === $localvar[0] ) echo " selected";
echo ">" . $value . "</options>";
}
echo '</select><br />';
If I echo $localvar[1] out I do get either 'kereskedő" or
"magánszemély", but when it passed through the conditional, it always
fails. What could be going on here?
Thanks in advance!

dombi


Alright... this works...

$localvar = array("{string variable from CMS}");
$choices = array("kereskedő", "magánszemély" ); //something screwy with
the character encoding between the database and this form...

echo '<select name="yourtype">';
foreach ($choices as $value) {
echo "<option value=\"" . $value . "\"";
if ( strlen(trim($value)) == strlen(trim($localvar)) ) echo " selected";
echo ">" . $value . "</options>";
}
echo '</select><br />';

Jul 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.