Getting ASCI Character sets - how?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Hadleigh
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Feb 04, 2003 10:32 am
Location: UK
Contact:

Getting ASCI Character sets - how?

Postby Hadleigh » Wed Feb 05, 2003 7:35 am

Hi,

This is a follow up from a previous post named inval problem......

Is there any function within php to convert to ASCI?

Thanks,

Hadleigh

Hurkle
New php-forum User
New php-forum User
Posts: 36
Joined: Tue Jan 07, 2003 8:45 am
Location: Minnesota, USA

Postby Hurkle » Wed Feb 05, 2003 1:14 pm

the 'ord' function should do the trick.

Try this:

Code: Select all


$str_char = 'a';

echo  "The ASCII value of str_char is: " . ord($str_char) . "<BR>";




hope that helps.

Hadleigh
New php-forum User
New php-forum User
Posts: 32
Joined: Tue Feb 04, 2003 10:32 am
Location: UK
Contact:

Postby Hadleigh » Wed Feb 05, 2003 1:39 pm

Thanks,

Here's the code in total.

Code: Select all

function ascii_encode($string){
   for ($i=0;$i<strlen($string);$i++) {
      $ascii_string.=ord(substr($string,$i)).'|';
   }
   $ascii=true;
   $ascii_array=explode("|",$ascii_string);
   for ($i=0;$i<strlen($string);$i++){
      if(!($ascii_array[$i]==32||$ascii_array[$i]==44
          ||$ascii_array[$i]==45||$ascii_array[$i]==48
          ||$ascii_array[$i]==49||$ascii_array[$i]==50
          ||$ascii_array[$i]==51||$ascii_array[$i]==52
          ||$ascii_array[$i]==53||$ascii_array[$i]==54
          ||$ascii_array[$i]==55||$ascii_array[$i]==56
          ||$ascii_array[$i]==57)){
         if($ascii_array[$i]==115&&$ascii_array[$i+1]==116){ // st
            $i++;
         }elseif($ascii_array[$i]==110&&$ascii_array[$i+1]==100){ // nd
            $i++;
         }elseif($ascii_array[$i]==114&&$ascii_array[$i+1]==100){ // rd
            $i++;
         }elseif($ascii_array[$i]==70&&$ascii_array[$i+1]==108&&$ascii_array[$i+2]==97&&$ascii_array[$i+3]==116){ // Flat
            $i+=3;   
         }elseif($ascii_array[$i]==85&&$ascii_array[$i+1]==110&&$ascii_array[$i+2]==105&&$ascii_array[$i+3]==116){ // Unit   
            $i+=3;
         }else{
            $ascii=false;
            $i=strlen($string);
         }
      }
   }
   return $ascii;
}


May have it's uses to someone (and save them a day!!!!).

regards,

Hadleigh.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 5 guests

cron