Jump to content

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;">

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.