note 44282 deleted from function.strip-tags by tomsommer
| From: | tomsommer@php.net | Date: | Tue, 20 Jul 2004 13:04:33 +0000 |
| Subject: | note 44282 deleted from function.strip-tags by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73689@lists.php.net to get a copy of this message | ||
Note Submitter: tompittlik@disfinite.net
----
A faster alternative to the "bbcode" fad ([B], [I] etc) which involves stripping out HTML
and then replacing [B]'s with <b>'s, [/B]'s with </b>'s etc is
simply to use strip_tags($message, "<b><i><u>"); etc. This saves a user
having to learn a useless language like bbcode.
When using this system you can still create custom simplified codes and skip them using strip_tags.
For instance, this easy quote code in an HTML style format:
<q name=Fred>The sky is blue</q> Can be skipped using strip_tags($message,
"<q>");
The <q> code could then be replaced after passing through the strip_tags filter.
<?
// This code strips out all HTML code
// excluding <b>, <i>, <u> and "<q>"
// "<q>" tags are then replaced with
// real HTML after the strip_tag function
$message = strip_tags($message, "<b><i><u><q></q>");
if (substr_count($message, "<q name=") > 0) {
// replace each quote one by one
$i = 0;
while ($i < substr_count($message, "<q name=")) {
// find first occurence of quote $i
$quote = strstr($message, "<q name=");
// find end of quote $i and remove rubbish
$quote = str_replace(strstr($quote, ">"), "", $quote) . ">";
// replace start of quote $i with html
$format_quote = str_replace("<q name=", "<fieldset><legend>",
$quote);
// replace end of quote $i with html
$format_quote = str_replace(">", " said: </legend>", $format_quote);
// replace old quote $i with formatted quote $i in message text
$message = str_replace($quote, $format_quote, $message);
++$i;
}
}
$message = str_replace("<q>", "<fieldset>", $message); // if any
anon quotes exist replace them
$message = str_replace("</q>", "</fieldset>", $message); // finally
replace all end quotes with html
?>