[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP Character processing

Posted on 2011-10-14
4
Medium Priority
?
177 Views
Last Modified: 2012-06-22
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;
  }
}
0
Comment
Question by:artwilkes
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1600 total points
ID: 36971289
Try:

for ( $i = 0 ; $i < 102 ; $i += 1){
  if ($pszBuffer[$i] < '@'){
    return FALSE;
  }
}
0
 
LVL 7

Assisted Solution

by:ziceva
ziceva earned 400 total points
ID: 36971313
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
 

Author Closing Comment

by:artwilkes
ID: 36971415
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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36971441
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question