NameSilo

Convert text to binary

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

edmarriner

Established Member
Impact
4
hi,

Is there any easy way in php to convert letters in to binary?
I just thought i would ask if there is any function before writing a long str_replace to replace the letters with binary code.

thanks,
-ed
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
hi,


thanks for repling so fast.

i had a look at that page but i cant work out how i could do this.
any ideas?

im want 2 basicly.

have a string and convert the string into binary.

<?php
$text = "some text here";
//some function to convert the text into binary
echo"$text";
?>

and it would output:

01110011 01101111 01101101 01100101 00100000 01110100 01100101 01111000 01110100 00100000 01101000 01100101 01110010 01100101
 
0
Close
See if you can use this..

PHP:
<html>
<head>
<title>Binary</title>
</head>

<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<textarea name="text" rows="10" cols="45"></textarea><br>
<input type="submit" name="submit" value="Convert!">
<input type="reset" value="Clear">
</form>

<?php

function binary($str)
{
  $text_array = explode("\r\n", chunk_split($str, 1));

  for($i = 0; $i < count($text_array) - 1; $i++)
  {
    $newstring .= substr("0000".base_convert(ord($text_array[$i]), 10, 2), -8);
  }
  return $newstring;
}

if(isset($_POST['submit']))
{
  $text = trim(strip_tags(stripslashes($_POST['text'])));
  $text = chunk_split(binary($text), 8, " ");
  
  echo $text;
}
?>

</body>
</html>
 
1
Close
It's pretty simple to write this function but it is also kinda impossible because of the many different character code tables. It's not like in the old Pascal times with the chr() function :)
 
0
Close
Wow,

Thankyou so much secondvision.
i am now for ever in in your debt. :hehe:

Thanks mch and 123finder.com to for your help.

That was fast, i only started the thread 50 mins ago. :tu:

Thanks once again, rep added to every who helped.

-ed
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back