SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Obsessive designer Infizi's Avatar
    Join Date
    May 2004
    Location
    North Pole
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP asc and chr functions (as in VB6)

    Ok, i cant find the equivilant function in PHP as in VB to convert an ascii to chr or visa-versa. Does anyone have a pre written function or anything else that will help me avoid having to write my own chr and asc function?

    Thanks Infizi
    New Design - PHP Slowly flowing in!

    Infizi Studio's

  2. #2
    SitePoint Guru enygmadae's Avatar
    Join Date
    Sep 2002
    Location
    Dallas, Tx.
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ord() and chr() won't work for you?
    PHP News, Views and Community: http://www.phpdeveloper.org

  3. #3
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you mean type-casting? I'm not sure what specifically the variable types are for VB.

    But if you want to convert a string to an integer, you could do:
    PHP Code:
     $string "abcdef";
     
    $var = (int) $string;
     
    //Which will turn it into an integer by adding ASCII numeric values, etc 
    or from integer to string
    PHP Code:
     $int 12345;
     
    $var = (string) $int
    Aaron Brazell
    Technosailor



  4. #4
    What a twist! Kings's Avatar
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    954
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like enygmadae, chr() and ord() is what you're looking for.
    Dennis Pallett - NoCertainty - My Personal Weblog
    The Web Network: ASPit | PHPit | WebDev-Articles
    Blogs: TalkFones | Holidayzer | PHPit Blog

  5. #5
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pack and unpack are useful when you need to convert several chars/codes at once:

    PHP Code:
    $str pack("c*"104101108108111);
    print 
    $str;
    print_r(unpack("c*"$str)); 

  6. #6
    Obsessive designer Infizi's Avatar
    Join Date
    May 2004
    Location
    North Pole
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah

    TY all
    New Design - PHP Slowly flowing in!

    Infizi Studio's


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •