Solved

Remove White Space

Posted on 2010-08-16
11
450 Views
Last Modified: 2013-12-13
Looks like your PHP is putting out a space before the <?xml ...?> declaration, which is technically invalid XML

How do I remove that? This is for Google Maps
<?
require('/fmicdev/geo_search_connect.php');
$center_lat = $_GET["latitude"];
$center_lng = $_GET["longitude"];
$radius = $_GET["radius"];
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}
$dom =new DOMDocument("1.0");
$node =$dom->createElement("markers");
$parnode =$dom->appendChild($node);
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}
$query = sprintf("SELECT concat(street,', ',city,', ',stateprov,', ',zip) AS address, custname, latitude, longitude, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM dealer HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20", mysql_real_escape_string($center_lat), mysql_real_escape_string($center_lng), mysql_real_escape_string($center_lat), mysql_real_escape_string($radius));
$result = mysql_query($query);
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}
header("Content-type: application/xml");
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $row['custname']);
  $newnode->setAttribute("address", $row['address']);
  $newnode->setAttribute("latitude", $row['latitude']);
  $newnode->setAttribute("longitude", $row['longitude']);
  $newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML();
?>

Open in new window


0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 125 total points
ID: 33451214
$dom->saveXML() should never have leading or trailing spaces.
What you need to make sure of, is that there is NO space before the first <? tag (line one of your code) and no space, linebreak or anything after the last ?> of your code.
Because PHP will treat any source code not encased in <? ?> as normal html data and output it to the browser/stream.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 33451290
There are no spaces. Do you have any other thoughts?
0
 
LVL 18

Assisted Solution

by:Jerry Miller
Jerry Miller earned 125 total points
ID: 33451334
It looks like you may have something after the ?>. You have a line 35 that appears blank, so there was most likely something there in your copy / paste.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 7

Author Comment

by:rgranlund
ID: 33451406
Please have a look again, cause I'm still getting this error:
[code]
<?php
require('/fmicdev/geo_search_connect.php');
$center_lat = $_GET["latitude"];
$center_lng = $_GET["longitude"];
$radius = $_GET["radius"];
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}
$dom =new DOMDocument("1.0");
$node =$dom->createElement("markers");
$parnode =$dom->appendChild($node);
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}
$query = sprintf("SELECT concat(street,', ',city,', ',stateprov,', ',zip) AS address, custname, latitude, longitude, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM dealer HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20", mysql_real_escape_string($center_lat), mysql_real_escape_string($center_lng), mysql_real_escape_string($center_lat), mysql_real_escape_string($radius));
$result = mysql_query($query);
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}
header("Content: application/xml");
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $row['custname']);
  $newnode->setAttribute("address", $row['address']);
  $newnode->setAttribute("latitude", $row['latitude']);
  $newnode->setAttribute("longitude", $row['longitude']);
  $newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML();
?>
[/code]

It appears to be commented out.
<?php
require('/fmicdev/geo_search_connect.php');
$center_lat = $_GET["latitude"];
$center_lng = $_GET["longitude"];
$radius = $_GET["radius"];
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}
$dom =new DOMDocument("1.0");
$node =$dom->createElement("markers");
$parnode =$dom->appendChild($node);
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}
$query = sprintf("SELECT concat(street,', ',city,', ',stateprov,', ',zip) AS address, custname, latitude, longitude, ( 3959 * acos( cos( radians('%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( latitude ) ) ) ) AS distance FROM dealer HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20", mysql_real_escape_string($center_lat), mysql_real_escape_string($center_lng), mysql_real_escape_string($center_lat), mysql_real_escape_string($radius));
$result = mysql_query($query);
$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}
header("Content: application/xml");
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $row['custname']);
  $newnode->setAttribute("address", $row['address']);
  $newnode->setAttribute("latitude", $row['latitude']);
  $newnode->setAttribute("longitude", $row['longitude']);
  $newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML();
?>

Open in new window

0
 
LVL 7

Author Comment

by:rgranlund
ID: 33451414
Also, it works fine in IE but not in Firefox.
0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33467206
can you post the xml output from firebug?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 33467286
white space problem solved
0
 
LVL 2

Expert Comment

by:Tiller79188231
ID: 33467336
what was it?
0
 
LVL 7

Author Comment

by:rgranlund
ID: 33468659
There was a space after the ?> in the include file.  It only took me about 8 hours to find it.  Geez.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34881964
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question