• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

HTML to ASCII converter

iBrightDev

Jay Street
NLC
NLC
make a file names str2ascii.php and paste the following code in it.

demo:
http://www.mct-hosting.com/str2ascii.php

PHP:
<?php

function str2ascii($string) {
    $ascii = array( );
    for( $i = 0; $i < strlen( $string ); $i++ ) $ascii[ $i ] = sprintf( "&#%d;", ord( $string{$i} ) );

    return implode( null, $ascii );
}

if($_POST){
	$find = array('&amp;#32;');
	$replace = array(' ');
	$str = htmlentities(str2ascii($_POST['plainTXT']), ENT_QUOTES);
	$fixedSTR = str_replace($find, $replace, $str);
	$str = $fixedSTR;

}

?> 

<form action="str2ascii.php" method="post">
Plain Text Here:<br>
<textarea name="plainTXT" cols="50" rows="8"><?=$_POST['plainTXT'];?></textarea>
<br><br>
Converted Ascii Text Here:<br>
<textarea name="asciiTXT" cols="50" rows="8" wrap="hard"><?=$str;?></textarea>
<br><br>
<input name="Submit" type="submit" value="Convert to Ascii">
</form>
 
Last edited:
Back
Top