Problem in string functions

consider the following line

$a=substr($contents,$pos,10);

the value of $a is available in my program after execution.
i have to check whether the value of $a is available.For that i have used the following lines.

$aa=“available”;
if ($a==$aa)
echo “same”;
else
echo “not same”;

i am getting result as “not same”.why?

Are you sure? What value does $pos have?

Try echoing the value of $a:

echo "a: '$a'<br/>";

The value of pos is a number.I have printed $a.The value is “available”.

No it isn’t. Your script would display ‘same’.

Try echoing $a with the code I posted. Copy & paste the result here. Including the single quotes (') !

Here is my code.I have attached a text file from which i read.
<?
$myfile = “whois.txt”;
$handle = fopen($myfile, “r”);
$contents = fread($handle, filesize($myfile));
fclose($handle);

$word=“appears to be”;
$pos=strpos($contents,$word);

$a=(substr($contents,$pos+13,10));
$aa=‘available’;

echo “a=”.$a;
echo “<br>”;
echo “aa=”.$aa;
echo “<br>”;

if ($a==$aa)
echo “same”;
else
echo"not same";
?>

Please do the echo like this:

echo "a: '$a' <br />";

The single quotes are important. They’ll show you if there is a space after ‘available’ (because ‘available’ is 9 characters, and you are taking 10 with the substr() ).

Here is the result

a:’ available’
not same

Do you see the space in front of available?
’ available’ is not the same as
‘available’

I am so sorry.I missed to watch that.Thank you very much.