Reply to Re: How to deal with all of those MS Word Funky characters

Your name:

Reply:


Posted by Leo Andrews on 10/28/27 11:24

gene.ellis@gmail.com wrote:
> Put simply, I have a text box, and people commonly cut + paste
> information into this text box from Microsoft word. The problem is that
> word has all types of funky characters (smart quotes, em-dashes), that
> the system (php-based) doesn't understand. Does anyone know of a way to
> filter out these Microsoft-specific characters? Does PHP have a special
> function for this? Thanks a lot!
>

Hooray I can actually be of use to this group for once. Yes, if you look
in the user notes on php.net for the htmlentities function you will see
an entry from mail at britlinks dot com (19-May-2004 05:27). I've listed
it below for reference. Mind you I'm sure the hardcore programmers on
this group will be able to formulate a one-line regexp for this and we
look forward to seeing it.

In the meantime, I hope this helps.


<?php
// strips slashes, and converts special characters to HTML equivalents
for string defined in $var
function htmlfriendly($var,$nl2br = false){
$chars = array(
128 => '&#8364;',
130 => '&#8218;',
131 => '&#402;',
132 => '&#8222;',
133 => '&#8230;',
134 => '&#8224;',
135 => '&#8225;',
136 => '&#710;',
137 => '&#8240;',
138 => '&#352;',
139 => '&#8249;',
140 => '&#338;',
142 => '&#381;',
145 => '&#8216;',
146 => '&#8217;',
147 => '&#8220;',
148 => '&#8221;',
149 => '&#8226;',
150 => '&#8211;',
151 => '&#8212;',
152 => '&#732;',
153 => '&#8482;',
154 => '&#353;',
155 => '&#8250;',
156 => '&#339;',
158 => '&#382;',
159 => '&#376;');
$var = str_replace(array_map('chr', array_keys($chars)), $chars,
htmlentities(stripslashes($var)));
if($nl2br){
return nl2br($var);
} else {
return $var;
}
}
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация