Jump to content

Death to Microsoft Word copy/paste in form fields


harley1387

Recommended Posts

Does anyone know how to replace MS Word characters for text that is copied/pasted (character ranges 128 -> 159) without using the chr function?

 

In a previous post http://www.phpfreaks.com/forums/index.php/topic,177458.0.html, PFMaBiSmAd mentioned:

 

chr() is only valid for ASCII characters. ASCII characters are only defined for 0 - 127. Using chr() for values greater than 127 is at your own risk.

 

Found this function elsewhere...but it uses chr:

 

function htmlfriendly($var,$nl2br = false){

$chars = array(
	128 => '€',
	130 => '‚',
	131 => 'ƒ',
	132 => '„',
	133 => '…',
	134 => '†',
	135 => '‡',
	136 => 'ˆ',
	137 => '‰',
	138 => 'Š',
	139 => '‹',
	140 => 'Œ',
	142 => 'Ž',
	145 => '‘',
	146 => '’',
	147 => '“',
	148 => '”',
	149 => '•',
	150 => '–',
	151 => '—',
	152 => '˜',
	153 => '™',
	154 => 'š',
	155 => '›',
	156 => 'œ',
	158 => 'ž',
	159 => 'Ÿ');

$var = str_replace(array_map('chr', array_keys($chars)), $chars, htmlentities(stripslashes($var)));		
if($nl2br){
	return nl2br($var);
} else {
	return $var;
}
}

 

Came across the following two ideas...but neither are ideal. There has to be a ready-made PHP function as I can't be the only one with this problem?!?!

 

Provides clean code for MS Word text that is copied/pasted: http://www.fckeditor.net/

 

"onpaste" disables pasting into a field...but not sure about the compatibility -- and it's a complete hack:

<input type="text" name="email" onpaste="event.returnValue=false;">

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.