Skip to Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

13.11 ASCII in HTML konvertieren

Problem

Sie möchten einfachen Text in brauchbar formatierten HTML-Code verwandeln.

Lösung

Codieren Sie zuerst die HTML-Entities mit htmlentities( ); transformieren Sie dann den Text in verschiedene HTML-Strukturen. Die in Listing 13.11 dargestellte Funktion pc_ascii2html( ) führt einige grundlegende Transformationen für Links und Absätze durch.

function pc_ascii2html($s) { $s = htmlentities($s); $grafs = split("\n\n",$s); for ($i = 0, $j = count($grafs); $i < $j; $i++) { // Links für alles herstellen, was wie eine HTTP- oder FTP-URL aussieht. $grafs[$i] = preg_replace('/((ht|f)tp:\/\/[^\s&]+)/', '<a href="$1">$1</a>',$grafs[$i]); // Links für E-Mail-Adressen. $grafs[$i] = preg_replace('/[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/i', ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi

Publisher Resources

ISBN: 9783868993271Purchase book