从HTML源中提取JSON并使用它

I have a URL like http://example.com - The HTML source of it is:

<html>
test
test2
{"customer":{"email":null,"is_eu":true"}
t
</html>

I want to get the JSON only from it then get anything from this JSON

My current code is here:

$whole_html = htmlspecialchars(file_get_contents("http:/example.com"));
preg_match('~\{(?:[^{}]|(?R))*\}~', $whole_html, $json);
$JsonResults = print_r($json, true);
$json_decoded = json_decode($JsonResults, true);
echo $json_decoded['customer']['email'];

But the result is empty page.

EDIT: The result of echo print_r($json, true) is:

Array ( [0] => {"customer":{"email":null,"is_eu":true} )

Any help would be appreciated.

Thanks!

The json string in the example html code above is incorrect. It must be like this

{"customer":{"email":null,"is_eu":true}}

You can use the following code.

$whole_html = file_get_contents("http:/example.com");
preg_match('~\{(?:[^{}]|(?R))*\}~', $whole_html, $json);
$arr = json_decode($json[0],true);
$email = $arr['customer']['email']; 
$is_eu = $arr['customer']['is_eu'];