Link to home
Start Free TrialLog in
Avatar of artwilkes
artwilkes

asked on

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;
  }
}
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of artwilkes
artwilkes

ASKER

Both solutions were great. David Baldwin's was right on,but ziceva's was also very helpfull.  Particulary the link to the ascii table.
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