Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

are == case sensitive? 3

Status
Not open for further replies.

namida

Programmer
Joined
May 29, 2003
Messages
101
Location
AU
When used with strings does
'string' == 'String' returns true?

or should i use a comparing function?
 
very!!!

question: are they equal?

____________________________________________________
$str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;

onpnt2.gif
 
ok so I'll change them to the same caps first. thx
 
just convert to upper or lower case
excert: $strLCaseAdage="there's many a slip twixt cup and lip";
echo $strLcaseAdage.&quot;<br />&quot;;
$strUcaseAdage=strtoupper($strLcaseAdage);
echo $strUcaseAdage.&quot;<br />&quot;;



____________________________________________________
$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;

onpnt2.gif
 
apart from the question above..
I just tried trimming the input from a form.
I tried inputing &quot;baa a &quot;

and then going to trim it and print it

echo $name.&quot;-\n&quot;;
$name = eregi_replace(&quot;[[:space:]]+&quot;, &quot; &quot;, trim($name));
echo $name.&quot;-&quot;;


but it turned out even before I delete all the extra whitespaces the form already submitted with only 1 space so my output looks like

baa a -
baa a-

I had expected it to be
baa a -
baa a-

I just want to know if this feature is actually already there in the html
 
The browser is using a proportional font so multiple spaces do not take as much room as you would expect. It's not your code, it's the way the browser displays it. To see what I mean use the View|Source option on the browser to confirm the spaces are still there.

If you want multiple spaces to show up as such you need either a fixed font or to use &nbsp in place of each space.
 
thx.. I get what you mean!
 
And note that unless you stick the output in <pre> tags (or similar), only one space is displayed by the browser if there are consecutive ones, so

echo &quot;word word2&quot;;

would display as

word word2
 
Also you seem satisfied modifying your input, which is often the right choice. But don't forget you can also use regular expressions to do nice things like ignore the whitespace, allowing you to compare without the need to either copy your input, or change it.

-Rob
 
I just want to make sure that my database isn't filled with spaces and what nots.

Since I'm building a forgot your password feature in my website so I need to compare some of the details.. like mother's name for example. SO I'm concerned whether they put 'Lily W' or ' lily W' or whatever and they won't be able to get their password.
So I'm stripping everything off then comparing them.

THanks a lot guys
 
A note on whitespace in HTML:

It is not the browser with the proportional font, it is HTML that is not whitespace specific. One space or fifty spaces make no difference.
That's why you are pretty free in formatting the HTML using whitespace, tabs, returns, spaces, newlines.

But, don't forget that the data itself (if in a database or within PHP) has the whitespace, eventhough HTML does not display it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top