/    Sign up×
Community /Pin to ProfileBookmark

PHP–>XML, works in IE and Firefox but not Safari

Hi Everybody,

I’m working on a Google Maps mashup that pulls data from a MySQL database with XML written in PHP. I’ve been developing and testing as I go along in Firefox, and it’s working fine, but for some reason Safari won’t read it as XML at all. It works in Firefox and IE, and when I show source in Safari it looks the same, but the page shows blank.

Here’s the code.

[CODE]<?php
require (“/home/cpdpn/public_html/lamp/v3apps/dbinfo.php”);

function parseToXML($htmlStr)
{
$xmlStr=str_replace(“n”,” “,$htmlStr);
$xmlStr=str_replace(“r”,””,$xmlStr);
$xmlStr=str_replace(“&”,’&amp;’,$xmlStr);
$xmlStr=str_replace(‘<‘,’&lt;’,$xmlStr);
$xmlStr=str_replace(‘>’,’&gt;’,$xmlStr);
$xmlStr=str_replace(‘”‘,’&quot;’,$xmlStr);
$xmlStr=str_replace(“‘”,”’,$xmlStr);
return $xmlStr;
}

//sets values for SQL queries
if (isset($_GET[‘pricerange’])){
$pricerangeint = $_GET[‘pricerange’];
}
else {
$pricerangeint = -1;
}
if (isset($_GET[‘restauranttype’])){
$restauranttype = $_GET[‘restauranttype’];
}
else {
$restauranttype = ‘All’;
}

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die(‘Not connected : ‘ . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die (‘Can’t use db : ‘ . mysql_error());
}

// select depending on parameters
if ($pricerangeint != -1 && $restauranttype == ‘All’) {
$query = “SELECT * FROM dguide_map WHERE price_range = ‘$pricerangeint'”;
}
else if ($restauranttype != ‘All’ && $pricerangeint == -1) {
$query = “SELECT * FROM dguide_map WHERE type = ‘$restauranttype'”;
}
else {
$query = “SELECT * FROM dguide_map”;
}

$result = mysql_query($query);
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}

header(“Content-type: text/xml”);

echo ‘<?xml version=”1.0″ encoding=”UTF-8″?>’;
// Start XML file, echo parent node
echo ‘<markers>’;

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){

//create and format the HTML for the info box marker
$htmlf = “<div class=’markerbox’>” . “<p class=’restaurantname’>” . $row[“name”] . “</p>”;

if ($row[“image_href”] != null){
$htmlf = $htmlf . “<img src='” . $row[“image_href”] . “‘ class=’restaurantimage’ />”;
}

$htmlf = $htmlf . $row[“excerpt”] . “<br />” . $row[“address”] . “<br /><a href='” . $row[“review_href”] . “‘ target=’_new’>Read a review</a>”;

$htmlf = $htmlf . “</div>”;

// ADD TO XML DOCUMENT NODE
echo ‘<marker ‘;
echo ‘name=”‘ . parseToXML($row[‘name’]) . ‘” ‘;
echo ‘html=”‘ . parseToXML($htmlf) . ‘” ‘;
echo ‘lat=”‘ . $row[‘lat’] . ‘” ‘;
echo ‘lng=”‘ . $row[‘lng’] . ‘” ‘;
echo ‘type=”‘ . $row[‘type’] . ‘” ‘;
echo ‘price_range=”‘ . $row[‘price_range’] . ‘” ‘;
echo ‘address=”‘ . parseToXML($row[‘address’]) . ‘” ‘;
echo ‘restauranttype=”‘ . parseToXML($row[‘type’]) . ‘” ‘;
echo ‘/>’;
}

// End XML file
echo ‘</markers>’;
?>[/CODE]

Can anyone figure it out, I would appreciate it so much. Thanks.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @phatalbert spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...