Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to convert text to binary code in PHP

1 Answer

0 votes
function text2bin($txt) 
{ 
    $bin = ''; 
    for ($i = 0; $i < strlen($txt); $i++) 
    { 
        $bin .= strlen(decbin(ord($txt[$i]))) < 8 ? 
                     str_pad(decbin(ord($txt[$i])), 8, 0, STR_PAD_LEFT) : decbin(ord($txt[$i])); 
        $bin .= " ";
    } 
    return $bin; 
} 
echo text2bin('PHP Programming'); 


/*
run:
    
01010000 01001000 01010000 00100000 01010000 01110010 01101111 01100111 01110010 
01100001 01101101 01101101 01101001 01101110 01100111 
       
*/


answered Aug 26, 2014 by avibootz
edited Jul 14, 2016 by avibootz

Related questions

1 answer 278 views
1 answer 76 views
1 answer 69 views
1 answer 73 views
1 answer 74 views
1 answer 67 views
...