# Convert special wordcharacters from Ajax to php?

**URL:** https://forum.kirupa.com/t/convert-special-wordcharacters-from-ajax-to-php/201531
**Category:** Uncategorized
**Created:** [September 22, 2006, 5:56am UTC](https://forum.kirupa.com/t/convert-special-wordcharacters-from-ajax-to-php/201531 "2006-09-22T05:56:21Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![manga](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@manga](https://forum.kirupa.com/u/manga)
#### Post date: [September 22, 2006, 5:56am UTC](https://forum.kirupa.com/t/convert-special-wordcharacters-from-ajax-to-php/201531/1 "2006-09-22T05:56:21Z")

</div>

hey all,

I work on some forms that post true AJAX to a PHP file.  
Now the problem is that i can retrieve special characters from the mysql DB and display them allrigth in a textarea field but when i save them back the specialscharacters become (??).

example:

in AJAX:  
fo=(document.myform);  
postvars=[];  
postvars[postvars.length]=“subject=”+encodeURIComponent(fo.subject.value);

AND in PHP to save

$subject=javascript\_to\_html(utf8\_decode(mysql\_escape\_string($\_POST[“subject”])));

and the php function is:

function javascript\_to\_html($text)  
{  
$matches = null ;  
preg\_match\_all(’/%u([0-9A-F]{4})/i’, $text, $matches) ;  
if (!empty($matches)) for($i = 0;$i \< sizeof($matches[0]);$i++)  
$text = str\_replace($matches[0][$i],  
‘&#’ . hexdec($matches[1][$i]) . ‘;’, $text) ;  
return $text ;  
}

anyhelp how i can save the specialcharacters good?

thanks in advance…

M
