Unstoppable Domains

Convert text to binary

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
0
•••
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
•••
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
•••
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
•••
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
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back