Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 1st, 2006, 02:25 AM
dombi
Guest
 
Posts: n/a
Default String comparison problems

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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.