|
|
|
|
|
|
| |
| <?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 | | | color codes for positive and negative numbers Categories : PHP, MySQL, Databases, HTML | | | Parses HTTP_USER_AGENT so that you can customize your site to different browsers Categories : HTML, PHP, Complete Programs | | | FormWizard reads a mysql table and generates automatically
a html formular in a html-table Categories : PHP, MySQL, HTML | | | Allows you to parse a deliniated string and put the individual fields in a SELECT option in a form Categories : HTML, PHP, Strings | | | Browser Detecor Class Categories : PHP Classes, PHP, HTML | | | Display Slashdot headers on your own site Categories : HTML and PHP, HTML, PHP | | | BBCode Formatting String Categories : PHP, HTML, Regexps, Arrays | | | webcam cam view image ispy browser independant Categories : Graphics, HTML, HTML and PHP, PHP | | | Builds JavaScript that updates the contents of one selector based on another. Categories : HTML, Java Script, PHP, Complete Programs, General | | | How to preset a text string in a textarea input field Categories : HTML, HTML and PHP, PHP, Beginner Guides | | | 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 | | | This script shows you the 7th latest php items from the mailing list archive on zend.com Categories : HTML, HTML and PHP, HTTP, PHP | | | The first step Guest Book ... ^^ Categories : MySQL, PHP, Apache, HTML, HTTP | | | GonxTabs : Create elegant HTML tabs based interface Categories : Navigation, HTML, HTML and PHP, PHP | |
| | | | matthew waygood wrote :1343
nice but i`d make one change:-
$textarray[$i] = preg_replace("/((ht|f)tp:\/\/[^\s&]+)/", "<a href=\"$1\">$1</a>", $textarray[$i]);
to
$textarray[$i] = preg_replace("/((http|ftp|https):\/\/[^\s&]+)/", "<a href=\"$1\">$1</a>", $textarray[$i]);
| |
|
|
|