WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : ASCII To HTML Converter
Categories : PHP, HTML, ASCII Click here to Update Your Picture
Murray Moffatt
Date : Aug 02nd 2005
Grade : 4 of 5 (graded 5 times)
Viewed : 14841
File : 4208.php
Images : No Images for this code example.
Search : More code by Murray Moffatt
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
/*
  Title: ASCII To HTML Converter

  Description: Accept a chunk of ASCII text and convert it
    into HTML suitable for outputting to a browser.
    Useful when you've got text stored in a database and you
    want to output it and automatically convert URLs into
    real links.

  Author: Murray Moffatt for A Web 4 U Designs

  History:
    2005-02-25 : Initial coding.
    2005-08-02 : Make stand-alone and include sample call for
      publishing on WeberDev.com.
*/

function ascii2html($text) {
 
// Encode any HTML tags
 
$text = htmlentities($text);

 
// Split the text into an array and treat each element as a paragraph
 
$textarray = split("\n", $text);

  for (
$i = 0, $j = count($textarray); $i < $j; $i++) {
   
// Turn HTTP and FTP URLs into links
   
$textarray[$i] = preg_replace("/((ht|f)tp:\/\/[^\s&]+)/", "<a href=\"$1\">$1</a>", $textarray[$i]);

   
// Turn email addresses into links
   
$textarray[$i] = preg_replace("/(\\S+@\\S+\\.\\w+)/", "<a href=\"mailto:$1\">$1</a>", $textarray[$i]);

   
// Add paragraphs
   
$textarray[$i] = "<p>" . $textarray[$i] . "</p>";
  }
  return
join("\n", $textarray);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ASCII To HTML</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="author" content="A Web 4 U Designs - www.aweb4u.co.nz">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Here is the result:</p>
<?php
$test
= <<<TEXTEND
This is the first paragraph.
Bold example: Use the <b> tag to get bold.
Visit http://www.weberdev.com today.
Don't forget to send an email to info@weberdev.com for more info.
TEXTEND;
echo
ascii2html($test);
?>
</body>
</html>



Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Browser Detecor Class
Categories : PHP Classes, PHP, HTML
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance.
Categories : HTML, PHP, HTML and PHP, Beginner Guides
GonxTabs : Create elegant HTML tabs based interface
Categories : Navigation, HTML, HTML and PHP, PHP
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
How to get the source of a site into an array.
Categories : Arrays, HTML, PHP
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a
Categories : HTML, PHP, PHP Classes, Regexps
Display Slashdot headers on your own site
Categories : HTML and PHP, HTML, PHP
Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but effective.
Categories : PHP, PHP Classes, HTML, HTML and PHP
class formHTML build your HTML Forms from PHP
Categories : PHP, PHP Classes, HTML and PHP, HTML
Script to check values being submitted by POST or GET method from a form. This script may help diagnose what variables are being supplied by a browser to other php scripts.
Categories : HTML, Variables, Debugging, PHP, HTTP
color codes for positive and negative numbers
Categories : PHP, MySQL, Databases, HTML
This script shows you the 7th latest php items from the mailing list archive on zend.com
Categories : HTML, HTML and PHP, HTTP, PHP
Formit 1.0. PHP Very easy to implement form-template(s) to email script. Works with multiple templates and HTML-format email. Only one file!
Categories : PHP, Email, HTML
 matthew waygood wrote :1343
nice but i`d make one change:-

$textarray[$i] = preg_replace("/((ht|f)tp:\/\/[^\s&]+)/", "&lt;a href=\"$1\"&gt;$1&lt;/a&gt;", $textarray[$i]); 

to

$textarray[$i] = preg_replace("/((http|ftp|https):\/\/[^\s&]+)/", "&lt;a href=\"$1\"&gt;$1&lt;/a&gt;", $textarray[$i]);