lorddemos90 Posted December 12, 2006 Share Posted December 12, 2006 I've managed to create a dynamic xml document in php that pulls information from a database. The problem is, some of the items in the database have "&" and other non-xml friendly characters in them. How can I add code into my program so that will display the characters as xml friendly?Here is my code:<? header('Content-type: text/xml'); ?><?php// display RSS 2.0 channel informationECHO <<<END<?xml version="1.0" encoding="utf-8"?><rss version="2.0"> <channel> <title>RSS Title</title> <link>http://www.rsswebsite.com</link> <description>RSS Description</description> <language>en-us</language> <generator>PHP/$phpversion</generator>END; ?><?php require_once('Connections/conn_customers.php'); ?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}}mysql_select_db($database_conn_customers, $conn_customers);$query_Recordset1 = "SELECT * FROM customers ORDER BY Contact ASC";$Recordset1 = mysql_query($query_Recordset1, $conn_customers) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?> <?php // display and loop each item.do {$title = $row_Recordset1['Contact Title'];$fname = $row_Recordset1['Contact'];$company = $row_Recordset1['Company'];ECHO <<<END <item> <title>$title</title> <name>$fname</name> <company>$company</company> <description>$mydescription...</description> <pubDate>$pubDate</pubDate> </item>END;} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); // Display end of RSS file dataECHO <<<END </channel></rss>END;mysql_free_result($Recordset1);?> Link to comment https://forums.phpfreaks.com/topic/30391-display-xml-friendly-special-characters/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.