[Home]PHP to convert HTML to text

HomePage | RecentChanges | Preferences | Newbie Help

Category PHP FAQ

Joe Alexander sez:


<?php
$fp=fopen ("filename","r");
$file=fread ($fp,filesize ("filename"));
$fclose($fp);
$pattern="'<[\/\!]*?[^<>]*?>'si";
$replace="";
$file = preg_replace ($pattern, $replace, $filev[$r]);
$fp=fopen ("filename.txt","w");
fputs ($fp,$file,strlen($file));
$fclose($fp);

//saves it in filename.txt
//to print in browser

$fp=fopen ("filename","r");
$file=fread ($fp,filesize ("filename"));
$fclose($fp);
$pattern="'<[\/\!]*?[^<>]*?>'si";
$replace="";
$file = preg_replace ($pattern, $replace, $filev[$r]);
print "$file";
?>

chris hamilton suggests:

(PHP 3>= 3.0.8, PHP 4 >= 4.0.0)

replace: $file = preg_replace ($pattern, $replace, $filev[$r]);
with:    $file = strip_tags ($file);


Comments --
HomePage | RecentChanges | Preferences | Newbie Help
This page is read-only | View other revisions
Last edited February 16, 2002 12:45 pm (diff)
Search:

This FAQ is happily hosted by Betadome Digital Media