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