Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

New modifier: escape_wquotes

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
charly71
Smarty Rookie


Joined: 10 Jun 2003
Posts: 6

PostPosted: Tue May 11, 2004 5:13 pm    Post subject: New modifier: escape_wquotes Reply with quote

This modifier escapes Ms Word chars like chr(146) or chr(151) from your text. It uses a simple PHP str_replace() function.
I have made this modifier because I had some dirty text stored in a mysql field... Mad

Code:

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * Type: modifier
 * Name: escape_wquotes
 * Version: 1.0
 * Date: 2004-05-11
 * Author: Carlo Sacripante sacripante[NOSPAM]@libero.it
 * Purpose: Escape chr(146) to chr(151) from MS Word text
 * Notes:  This modifier uses a simple PHP str_replace function to
 *  replace single and double quotes characters from a Microsoft Word
 *    "cut and paste like" string, with an HTML encoded string.
 *
 * Example smarty code:
 *
 * {$dirtyString|escape_wquotes}
 *
 *
 * -------------------------------------------------------------
 */

function smarty_modifier_escape_wquotes ($text)

{
   $badwordchars=array(
                           chr(145),
                           chr(146),
                           chr(147),
                           chr(148),
                           chr(151)
                           );
   $fixedwordchars=array(
                           "& acute;",  //no blank space after & <- erase this comment ;-)
                           "& acute;",
                           '& quot;',
                           '& quot;',
                           '& mdash;'
                           );
   return str_replace($badwordchars,$fixedwordchars,$text);
}

?>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP