MARC
Mailing list ARChives
FOLDOC
Computing Dictionary
raw-text to HTML Formatter
Title: raw-text to HTML Formatter
Contributor: Jeffrey Paul (aka sneak)
Last Update: Friday March 31 00:22 EDT 2000
<?php
/**********************************************************************
* string htmlescape(string $input) *
**********************************************************************
* This function will take a given input string and strip out all *
* high-ascii characters, and properly replace © (0xA9) and *
* ® (0xA8) with '©' and '®', respectively. *
* *
* It will also replace ampersands (&) with '&', *
* quotation marks (") with '"', and less than *
* (<) and greater than (>) signs with their *
* appropriate html substitute ('<' and '>', *
* respectively). *
* *
* It strips all ascii below 32 except for tabs, newlines, *
* form feeds, and carriage returns. *
* *
* This would be suitable for posting code or other textual data in *
* a <pre></pre> tag set, while retaining the printable *
* and html-escapable data and format. *
* *
* As usual, more could be done, but I'm lazy. See: *
* http://www.w3.org/TR/1999/REC-html401-19991224/sgml/entities.html *
* *
* Oh, it's also really slow. It could probably be done faster *
* with ereg_replace() or somesuch, but it's a hack. *
**********************************************************************/
function htmlescape ($input) {
$output = '';
while(1) {
if($input == '')
break;
$ch = substr($input,0,1);
$templen = strlen($input) - 1;
$input = substr($input,1,$templen);
if($ch == "\\xA9") $ch = '©';
if($ch == "\\xA8") $ch = '®';
if($ch == '&') $ch = '&';
if($ch == '"') $ch = '"';
if($ch == '<') $ch = '<';
if($ch == '>') $ch = '>';
if(ord($ch) > 126) $ch = '';
if(ord($ch) < 9) $ch = '';
if(ord($ch) == 11) $ch = '';
if(ord($ch) > 14 && ord($ch) < 32) $ch = '';
$output = $output . $ch;
}
return($output);
}
/**********************************************************************/
?>
Anyone who wishes to make additions or changes to this
PHP Tip email them to webmaster@linuxguruz.org
This document is Copyright (c) 1999, 2000 by LinuxGuruz
Return to the LinuxGuruz PHP Tutorials Page Return to the LinuxGuruz Main Page
www.PHP.net Search Engine
Restrict the search to:
Whole site
Online documentation
PHP 3.0 Mailing List
PHP Developers' List
PHP Documentation List
PHPLIB Mailing List
PHPLIB Developers' List
Site PHP 3.0 source code
Copyright © 1999, 2000 The PHP Development Team.
Return to the LinuxGuruz PHP Tutorials Page
Return to the LinuxGuruz Main Page