note 60379 added to function.ereg-replace

From: Date: Thu, 05 Jan 2006 11:18:03 +0000
Subject: note 60379 added to function.ereg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-101245@lists.php.net to get a copy of this message
I was searching a way to remove all html-tags in a text string, but did not find the right code segment... I have written a little bit code that removes any html-tags, changing BR-Tags in newlines. anyway, hope, it will be usefull for someone function ch_remove_html($txt='') { // call with a string // returns only txt (html tags removed) $toremove = 1; // start loop $txt = ereg_replace("<[/]?br>","\n",$txt); // change to newline $txt_size = strlen($txt); // current length while ($toremove == 1) { $txt = ereg_replace("(.*)<[/]?.*>(.*)","\\1\\2",$txt); // remove if any if ($txt_size == strlen($txt)) { $toremove=0; // if no more html tags avaiable, cancel loop } $txt_size=strlen($txt); // size after any removings } // echo $txt; return $txt; } ---- Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60379 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60379&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60379&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60379&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60379&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60379&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60379&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60379&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60379&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101245) next »