Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on


See attached. This produces the following:

addr = 13511 Orchard Gate Road

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 3: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xA0 0x20 0x50 0x6F in /homepages/38/d170218105/htdocs/GVHA/geocode_custs.php on line 20

Warning: simplexml_load_string() [function.simplexml-load-string]: <name>13511 Orchard Gate Road  Poway, CA USA</name> in /homepages/38/d170218105/htdocs/GVHA/geocode_custs.php on line 20

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /homepages/38/d170218105/htdocs/GVHA/geocode_custs.php on line 20

What is the problem?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Where is the data?  This is a data-dependent problem.
// geocode all LSS Customers
function getCurlData($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0); //Change this to a 1 to return headers
    //    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    return $data;

  function getLatLon($street, $city, $country) {
    $matches = array();
    $latlon = array();
    $loc = urlencode($street . ' ' . $city . ' ' . $country);
    $url = '' . $loc;
    $xml = simplexml_load_string(getCurlData($url)) or die("");
    if (isset($xml->Response->Placemark)) {
      $str = $xml->Response->Placemark->Point->coordinates;
      preg_match_all("/-*[0-9.]*(?=,)/", $str[0], $matches);
      $latlon[] = $matches[0][2];//latitude
      $latlon[] = $matches[0][0];//longitude
    return $latlon;
$Host = "localhost";
$User = "dbo123";
$Password = "abcxyz";
$DBName = "db123";
$Link = mysql_connect ($Host, $User, $Password);	
// get current date in mysql format
$qry = "SELECT * from homeowner order by lot";
$res = mysql_db_query ($DBName, $qry, $Link);
$nc = mysql_num_rows ($res);
$dates = array();
$numgc = array();
$nd = 0;
$na = 0;
$np = 0;
$nj = 0;
$custname = array();
$addrs = array();
$reason = array();
// Initialize delay in geocode speed
$delay = 0;
//Do em all
$fn = "xmlfile.xml";
$fp = fopen($fn, "w");
for ($i = 0; $i < $nc; $i++) {	
	$h = mysql_fetch_array($res);
	$nf = true;
	$cs = "Poway, CA";
	$addr = $h['number'] . " " . $h['street'];
	echo "addr = " . $addr . "<br>";
	while ($nf) {		
		$latlon = getLatLon($addr, $cs, "USA");
		if ($latlon[0] == "") {
		} else {
			$nf = false;
 // put write xml in here
	$str = "<marker lat=" . chr(34) . $latlon[0] . Chr(34) . " lng=" . chr(34) . $latlon[1] . chr(34) . " html=" . chr(34) . $addr . chr(34);
	$str = $str . "lot=" . chr(34) . $h['lot'] . chr(34) . "/>";
	fwrite($fp, $str);


Open in new window

Avatar of Richard Korts


The data is in the database table called homeowner. That's why I put the echo in the code so I could see what was being passed.

If you like I can dump the table as sql & post it.

No, I don't think I need to see that.  I think we need to see the XML string created on line 20.  For my address, you get this (click the link)
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Let me try it, might be tomorrow.

You know, other projects..................

10-4.  You might want to think about separating those compound statements. When you have something like this...

$xml = simplexml_load_string(getCurlData($url))

... it is kind of hard to figure out the contents returned by getCurlData() and since that is the thing that is tripping the SimpleXML function, it's something we need to see.

Please post back when it's convenient, ~Ray
Works great.

The MAIN problem is that there are unprintable characters in the data (street name)

Look for my next question on that if you are interested.