Help - Search - Member List - Calendar
Full Version: compare strings?
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
Ron Eggler @ work
Hi,

I want to compare two Strings and I don't know how. Following HTML-Output is
the result of the below code. why?
The Strings are the same but the if() is false, why? Thank you!
HTML
[Email Removed]
<br>
[Email Removed] was passed<br>
not yet!<br>

[PHP]
echo $buffer."<br>n";
echo $email." was passed<br>n";
if ($buffer==$email)
{
echo "string already exists!<br>n";
return true;
}
else
{
echo "not yet!<br>n";
}
[/PHP]

Colin McKinnon
Ron Eggler @ work wrote:

QUOTE
Hi,

I want to compare two Strings and I don't know how. Following HTML-Output
is the result of the below code. why?
The Strings are the same but the if() is false, why? Thank you!
[HTML]
[Email Removed]
<br
[Email Removed] was passed<br
not yet!<br

They're not the same - $buffer ends in a newline char.

try

if (trim($buffer)==$email){

although that does not allow for capitalization.

HTH

C.

Exyle
the eregi function should be what you're looking for.

eregi($buffer, $email)

if $email contains $buffer than it will return true. You can also use
regular expressions. eregi is case insensitive (eg it will interpret 'A'
and 'a' as the same thing). the ereg function does the same thing only
it's case sensative.

Ron Eggler @ work wrote:
QUOTE
Hi,

I want to compare two Strings and I don't know how. Following HTML-Output is
the result of the below code. why?
The Strings are the same but the if() is false, why? Thank you!
HTML
[Email Removed]
<br
[Email Removed] was passed<br
not yet!<br

[PHP]
echo $buffer."<br>n";
echo $email." was passed<br>n";
if ($buffer==$email)
{
echo "string already exists!<br>n";
return true;
}
else
{
echo "not yet!<br>n";
}
[/PHP]




PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.