PHP Character processing

This code always fails, return FALSE, even thought the first character is a B or 66.
I'm not sure how to format character processing in PHP.
My desire is the see if there are any characters below 64 that are not vaild in this buffer.
Seems like this should be simple, but it's not.
Thanks
for ( $i = 0 ; $i < 102 ; $i += 1){
  if ($pszBuffer[$i] < 64){
    return FALSE;
  }
}
artwilkesAsked:
Who is Participating?
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
Try:

for ( $i = 0 ; $i < 102 ; $i += 1){
  if ($pszBuffer[$i] < '@'){
    return FALSE;
  }
}
0
 
zicevaConnect With a Mentor Commented:
Not sure that this is what you are looking for, but you could use this functions to do character processing:

ord('A') returns 65
chr(65) returns 'A'

So you should end up comparing ord($pszBuffer[$i]) with whatever integer value you need as you find all of them here: http://www.asciitable.com/


0
 
artwilkesAuthor Commented:
Both solutions were great. David Baldwin's was right on,but ziceva's was also very helpfull.  Particulary the link to the ascii table.
0
 
Dave BaldwinFixer of ProblemsCommented:
This PHP page clearly shows (in color) what the difference between PHP's interpretation of '< 64' and '< "@" ' is.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>PHP Buffer Check</title>
</head>
<body>
<h1>PHP Buffer Check</h1>
<?php 
$pszBuffer = "This code always fails, return FALSE, even thought the first character is a B or 66. I'm not sure how to format character processing in PHP. My desire is the see if there are any characters below 64 that are not vaild in this buffer. Seems like this should be simple, but it's not.";

for ( $i = 0 ; $i < 102 ; $i++){
  if ($pszBuffer[$i] < 64){
    echo $i.":<span style='color: #ffffff;background-color: #ff0000;'>".$pszBuffer[$i]."</span>&nbsp;";
  }
}
echo "<br><br>";
for ( $i = 0 ; $i < 102 ; $i++){
  if ($pszBuffer[$i] < '@'){
    echo $i.":<span style='color: #ffffff;background-color: #ff0000;'>".$pszBuffer[$i]."</span>&nbsp;";
  }
}
 ?>
</body>
</html>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.