473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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

Jul 1 '06 #1
1 1581
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool This article makes a detailed comparison among SourceAnyWhere, SourceOffSite, VSS...
5
by: mayamorning123 | last post by:
A comparison among six VSS remote tools including SourceOffSite , SourceAnyWhere, VSS Connect, SourceXT, VSS Remoting, VSS.NET To view the full article, please visit...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
46
by: yadurajj | last post by:
Hello i am newbie trying to learn C..I need to know about string comparisons in C, without using a library function,...recently I was asked this in an interview..I can write a small program but I...
5
by: MaSTeR | last post by:
Can anyone provide a practical short example of why in C# I shouldn't compare two strings with == ? If I write this in JAVA String string1 = "Widget"; if (string1 == "Widget") ...
37
by: jortizclaver | last post by:
Hi, I'm about to develop a new framework for my corporative applications and my first decision point is what kind of strings to use: std::string or classical C char*. Performance in my system...
26
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I...
11
by: Sudzzz | last post by:
Hi, I'm trying to convert a string something like this "{201,23,240,56,23,45,34,23}" into an array in C++ Please help. Thanks, Sudzzz
16
by: yu_kuo | last post by:
Is there any comparison data on perfomance difference between std::string and c style string? Or maybe if there are source code which could be used to measuer on different compiler/platform, in a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.