Connecting Tech Pros Worldwide Help | Site Map

String comparison problems

  #1  
Old July 1st, 2006, 02:25 AM
dombi
Guest
 
Posts: 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

  #2  
Old July 1st, 2006, 03:45 AM
dombi
Guest
 
Posts: n/a

re: String comparison problems


On 2006-06-30 18:30:16 -0700, dombi <dombi@cox.net> said:
[color=blue]
> 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[/color]

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 />';

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in string comparison (Non-English windows) Usman Jamil answers 9 December 21st, 2006 03:45 AM
String comparison doesn't work as expected Zeng answers 1 November 17th, 2005 02:21 AM
C# String Comparison, IndexOf and Related BILL answers 5 November 16th, 2005 10:31 AM
string comparison junky_fellow@yahoo.co.in answers 26 November 15th, 2005 01:44 AM