1

I have a form where I input a keyword to automatically search Google for this term. Its a standard HTML Form like this: <form method="POST" action="gSearch.php" id="gSearch"></form>

I have declared UTF-8 in the documents section via a meta field <meta charset="utf-8">

The form data itself is send to the PHP script via AJAX like this:

var $form = $(this);
var $inputs = $form.find("input");
var serializedData = $form.serialize();

$inputs.prop("disabled", true);

request = $.ajax({
    url: "gSearch.php",
    type: "post",
    dataType: 'json',
    data: serializedData
});

and within the PHP file I use Simple HTML Dom to scrape the website, loop through the results and save them in my database. The database tables' collation is set to utf8_unicode_ci .

Problem: Special characters do not get scraped at all! Lets say the title is Prägnanter Titel then it only outputs Pr. It basically stops right when there is a special character.

Attemps: I tried to solve the issue by using htmlspecialchars($str, ENT_QUOTES, "UTF-8") as well as adding header('Content-Type: text/html; charset=utf-8') to my PHP file (is this correct?) but no luck.

Anyone else an idea where the problem is and what I can do to solve it?

Thanks, Dom

Charles Ingalls
  • 4,521
  • 5
  • 25
  • 33
  • See these similar questions about dealing with text encodings: http://stackoverflow.com/questions/12351776/character-encoding-issue-with-php-simple-html-dom-parser and http://stackoverflow.com/questions/4550903/simple-html-dom-character-encoding-issue . – i alarmed alien Aug 15 '14 at 14:01
  • Thanks @girlwithglasses, I already read those posts but unfortunately it didn't solve my problem. It pretty much suggest possible solutions that I already have in place. – Charles Ingalls Aug 15 '14 at 14:12
  • Does the data coming from your jQuery script definitely have the special characters in place? i.e. if you print out the json, are all the special characters there? – i alarmed alien Aug 15 '14 at 19:11

0 Answers0