Replacing XML hexidecimal &#xD;&#xA; with <br>

Hi,

I am new to php and need some help. The version of php that I am using is 4.3.11, so any suggestions have to work under this version.

I have a Microsoft SQL Server database which holds XML in an ntext column. I use an ODBC data connection to retrieve the data and then try and display it.

My current code is:

[php]<?php

ob_start(“ob_gzhandler”);

require ‘…/includes/backtrace.php’;
require ‘…/includes/db_odbc.php’;
require ‘…/includes/theme.php’;

$site = $_GET[‘site’];
if (!$site) $site = ‘databaseName’;

db_connect($site, ‘userName’, ‘password’);

$rs = db_query(
‘SELECT
*
FROM
[DB].[dbo].[table][tr][td]
WHERE
Sequence = %d’, $_GET[‘Sequence’]);

$r = db_fetch_array($rs);

$xml = array_pop($r);

echo “

SELECT * FROM [DB].[dbo].[table][tr][td] WHERE Sequence = {$_GET[‘Sequence’]}
”;

print_r($r);

echo “


”, htmlspecialchars($xml);

db_close();

?>[/php]

I think that by using htmlspecialchars I am also corrupting that output as the value from the database contains the hexidecimal values for carriage return line feed.

Sample data from database:

[/td][/tr][/table][/td][/tr][/table]<error host="HOST" type="System.Web.HttpException" message="Unable to use SQL Server because either ASP.NET version 2.0 Session State is not installed on the SQL server, or ASP.NET does not have permission to run the dbo.TempGetVersion stored procedure. If the ASP.NET Session State schema has not been installed, please install ASP.NET Session State SQL Server version 2.0 or above. If the schema has been installed, please grant execute permission on the dbo.TempGetVersion stored procedure to either the ASP.NET application pool identity, or the Sql Server user specified in the sqlConnectionString attribute." source="System.Web" detail="System.Web.HttpException (0x80004005): Unable to use SQL Server because either ASP.NET version 2.0 Session State is not installed on the SQL server, or ASP.NET does not have permission to run the dbo.TempGetVersion stored procedure. If the ASP.NET Session State schema has not been installed, please install ASP.NET Session State SQL Server version 2.0 or above. If the schema has been installed, please grant execute permission on the dbo.TempGetVersion stored procedure to either the ASP.NET application pool identity, or the Sql Server user specified in the sqlConnectionString attribute.&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.SqlPartitionInfo.GetServerSupportOptions(SqlConnection sqlConnection)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.SqlPartitionInfo.InitSqlInfo(SqlConnection sqlConnection)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.SqlStateConnection..ctor(SqlPartitionInfo sqlPartitionInfo, TimeSpan retryInterval)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.GetConnection(String id, Boolean&amp; usePooling)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean&amp; locked, TimeSpan&amp; lockAge, Object&amp; lockId, SessionStateActions&amp; actionFlags)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.GetItemExclusive(HttpContext context, String id, Boolean&amp; locked, TimeSpan&amp; lockAge, Object&amp; lockId, SessionStateActions&amp; actionFlags)&#xD;&#xA; at System.Web.SessionState.SessionStateModule.GetSessionStateItem()&#xD;&#xA; at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData)&#xD;&#xA; at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()&#xD;&#xA; at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)" time="2013-07-16T11:14:12.7190788+01:00" statusCode="500"> <serverVariables> <item name="ALL_HTTP"> <value string="HTTP_CONNECTION:Keep-Alive&#xD;&#xA;HTTP_VIA:1.1 SPHERE&#xD;&#xA;HTTP_ACCEPT:image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*&#xD;&#xA;HTTP_ACCEPT_LANGUAGE:en-GB&#xD;&#xA;HTTP_COOKIE:__utma=1.1030959409.1363176217.1373555109.1373625429.140; __utmz=1.1363176217.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); AcceptCookies=True; ASP.NET_SessionId=uapko0rlgz55noblacv2nz3b&#xD;&#xA;HTTP_HOST:localhost&#xD;&#xA;HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)&#xD;&#xA;" /> </item> <item name="ALL_RAW"> <value string="Connection: Keep-Alive&#xD;&#xA;Via: 1.1 SPHERE&#xD;&#xA;Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*&#xD;&#xA;Accept-Language: en-GB&#xD;&#xA;Cookie: __utma=1.1030959409.1363176217.1373555109.1373625429.140; __utmz=1.1363176217.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); AcceptCookies=True; ASP.NET_SessionId=uapko0rlgz55noblacv2nz3b&#xD;&#xA;Host: localhost&#xD;&#xA;User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)&#xD;&#xA;" /> </item> <item name="APPL_MD_PATH"> <value string="/LM/W3SVC/6/ROOT" /> </item> <item name="APPL_PHYSICAL_PATH"> <value string="C:\Website\" /> </item> <item name="AUTH_TYPE"> <value string="" /> </item> <item name="AUTH_USER"> <value string="" /> </item> <item name="AUTH_PASSWORD"> <value string="" /> </item> <item name="LOGON_USER"> <value string="" /> </item> <item name="REMOTE_USER"> <value string="" /> </item> <item name="CERT_COOKIE"> <value string="" /> </item> <item name="CERT_FLAGS"> <value string="" /> </item> <item name="CERT_ISSUER"> <value string="" /> </item> <item name="CERT_KEYSIZE"> <value string="" /> </item> <item name="CERT_SECRETKEYSIZE"> <value string="" /> </item> <item name="CERT_SERIALNUMBER"> <value string="" /> </item> <item name="CERT_SERVER_ISSUER"> <value string="" /> </item> <item name="CERT_SERVER_SUBJECT"> <value string="" /> </item> <item name="CERT_SUBJECT"> <value string="" /> </item> <item name="CONTENT_LENGTH"> <value string="0" /> </item> <item name="CONTENT_TYPE"> <value string="" /> </item> <item name="GATEWAY_INTERFACE"> <value string="CGI/1.1" /> </item> <item name="HTTPS"> <value string="off" /> </item> <item name="HTTPS_KEYSIZE"> <value string="" /> </item> <item name="HTTPS_SECRETKEYSIZE"> <value string="" /> </item> <item name="HTTPS_SERVER_ISSUER"> <value string="" /> </item> <item name="HTTPS_SERVER_SUBJECT"> <value string="" /> </item> <item name="INSTANCE_ID"> <value string="6" /> </item> <item name="INSTANCE_META_PATH"> <value string="/LM/W3SVC/6" /> </item> <item name="LOCAL_ADDR"> <value string="255.255.255.255" /> </item> <item name="PATH_INFO"> <value string="/Error.aspx" /> </item> <item name="PATH_TRANSLATED"> <value string="C:\Website\Error.aspx" /> </item> <item name="QUERY_STRING"> <value string="aspxerrorpath=/Default.aspx" /> </item> <item name="REMOTE_ADDR"> <value string="255.255.255.255" /> </item> <item name="REMOTE_HOST"> <value string="255.255.255.255" /> </item> <item name="REMOTE_PORT"> <value string="30236" /> </item> <item name="REQUEST_METHOD"> <value string="GET" /> </item> <item name="SCRIPT_NAME"> <value string="/Error.aspx" /> </item> <item name="SERVER_NAME"> <value string="localhost" /> </item> <item name="SERVER_PORT"> <value string="80" /> </item> <item name="SERVER_PORT_SECURE"> <value string="0" /> </item> <item name="SERVER_PROTOCOL"> <value string="HTTP/1.1" /> </item> <item name="SERVER_SOFTWARE"> <value string="Microsoft-IIS/7.5" /> </item> <item name="URL"> <value string="/Error.aspx" /> </item> <item name="HTTP_CONNECTION"> <value string="Keep-Alive" /> </item> <item name="HTTP_VIA"> <value string="1.1 SPHERE" /> </item> <item name="HTTP_ACCEPT"> <value string="image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" /> </item> <item name="HTTP_ACCEPT_LANGUAGE"> <value string="en-GB" /> </item> <item name="HTTP_COOKIE"> <value string="__utma=1.1030959409.1363176217.1373555109.1373625429.140; __utmz=1.1363176217.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); AcceptCookies=True; ASP.NET_SessionId=uapko0rlgz55noblacv2nz3b" /> </item> <item name="HTTP_HOST"> <value string="localhost" /> </item> <item name="HTTP_USER_AGENT"> <value string="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)" /> </item> </serverVariables> <queryString> <item name="aspxerrorpath"> <value string="/Default.aspx" /> </item> </queryString> <cookies> <item name="__utma"> <value string="1.1030959409.1363176217.1373555109.1373625429.140" /> </item> <item name="__utmz"> <value string="1.1363176217.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)" /> </item> <item name="AcceptCookies"> <value string="True" /> </item> <item name="ASP.NET_SessionId"> <value string="123456789" /> </item> </cookies> </error>

Output that is displayed (scroll to the end of the line to see the corruption):

<error host="HOST" type="System.Web.HttpException" message="Unable to use SQL Server because either ASP.NET version 2.0 Session State is not installed on the SQL server, or ASP.NET does not have permission to run the dbo.TempGetVersion stored procedure. If the ASP.NET Session State schema has not been installed, please install ASP.NET Session State SQL Server version 2.0 or above. If the schema has been installed, please grant execute permission on the dbo.TempGetVersion stored procedure to either the ASP.NET application pool identity, or the Sql Server user specified in the sqlConnectionString attribute." source="System.Web" detail="System.Web.HttpException (0x80004005): Unable to use SQL Server because either ASP.NET version 2.0 Session State is not installed on the SQL server, or ASP.NET does not have permission to run the dbo.TempGetVersion stored procedure. If the ASP.NET Session State schema has not been installed, please install ASP.NET Session State SQL Server version 2.0 or above. If the schema has been installed, please grant execute permission on the dbo.TempGetVersion stored procedure to either the ASP.NET application pool identity, or the Sql Server user specified in the sqlConnectionString attribute.&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.SqlPartitionInfo.GetServerSupportOptions(SqlConnection sqlConnection)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.SqlPartitionInfo.InitSqlInfo(SqlConnection sqlConnection)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.SqlStateConnection..ctor(SqlPartitionInfo sqlPartitionInfo, TimeSpan retryInterval)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.GetConnection(String id, Boolean&amp; usePooling)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean&amp; locked, TimeSpan&amp; lockAge, Object&amp; lockId, SessionStateActions&amp; actionFlags)&#xD;&#xA; at System.Web.SessionState.SqlSessionStateStore.GetItemExclusive(HttpContext context, String id, Boolean&amp; locked, TimeSpan&amp; lockAge, Object&amp; lockId, SessionStateActions&amp; actionFlags)&#xD;&#xA; at System.Web.SessionState.SessionStateModule.GetSessionStateItem()&#xD;&#xA; at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData)&#xD;&#xA; at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()&#xD;&#xA; at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)" time="2013-07-16T11:14:12.7190788+01:00" statusCode="500"> <serverVariables> <item name="ALL_HTTP"> <value string="HTTP_CONNECTION:Keep-Alive&#xD;&#xA;HTTP_VIA:1.1 SPHERE&#xD;&#xA;HTTP_ACCEPT:image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*&#xD;&#xA;HTTP_ACCEPT_LANGUAGE:en-GB&#xD;&#xA;HTTP_COOKIE:__utma=1.1030959409.1363176217.1373555109.1373625429.140; __utmz=1.1363176217.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); AcceptCookies=True; ASP.NET_SessionId=uapko0rlgz55noblacv2nz3b&#xD;&#xA;HTTP_HOST:localhost&#xD;&#xA;HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)&#xD;&#xA;" /> </item> <item name="ALL_RAW"> <value string="Connection: Keep-Alive&#xD;&#xA;Via: 1.1 SPHERE&#xD;&#xA;Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*&#xD;&#xA;Accept-Language: en-GB&#xD;&#xA;Cookie: __utma=1.1030959409.1363176217.1373555109.1373625429.140; __utmz=1.1363176217.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); AcceptCookies=True; ASP.NET_SessionId=uapko0rlgz55noblacv2nz3b&#xD;&#xA;Host: localhost&# {(OPL+N.lt‚8L(KðKMessage	bPLÈ‚°	i ‚ˆ€.ÏžTä‚°‚À€(KStatusCode	Pxj8ƒ	db_closeWƒXƒsql[8ƒxƒconn_Xƒ˜ƒconnCxƒ8„aresultGøl؃K¸ƒ„db_fetch_objectN؃À„connàŠP·˜ƒ`„ odbc_execº8„€„aresult¾`„ „conn¢€„ølsql¦„à„connªÀ„…odbc_closepŸ‚|‘à„(…•…conn™ˆ’p…db_fetch_arrayœH……rspŸ‚|€p…¸…odbc_num_rows‡…Ø…x‹¸…(©rs(© † db_resultrrayòø…@†rspŸ‚|ö †p†odbc_fetch_array1ü@††xàp†¨«rs䨫؆ db_get_assocñûë°†ø†rspŸ‚|ï؆ ‡odbc_resultÒø†@‡xÖ ‡(®rsÚ(®ˆ‡èJÁ`‡¨‡aresult|ň‡È‡rowsɨ‡hˆrowÍ°ˆˆÿÿÿÿðñû0è‡8ˆarray_shift7ˆP‰rows>H=ȇˆdb_fetch_array hˆ°ˆrows$ˆè‡aresult(À‰ðˆmatch,Ј‰initðˆ0‰FALSE‰pÏ?args8ˆð‰row±‰p‰À‰call_user_func_array‰Ðˆ/(%d|%s|%%|%f|%b)/Í7 P‰Šarray_shiftsð‰±rowwÐÏXŠinit{8ŠøŠargs‹ Š==ÿÿÿÿðñûbxŠÀŠmatch‚|f ŠP‹%dÀî „oXŠ‹matchaSøŠxŠ aXÀŠx‹array_shiftðñû_P‹˜‹%spŸ‚|Cx‹¸‹argsG˜‹è‹db_escape_stringM¸‹ŒpŸ‚|%%±è‹0Œarray_shiftM´ŒPŒ˜%^¸0ŒpŒargs¼PŒŒ%f pŒ¸Œarray_shiftpŸ‚|§ŒØŒ%b«¸ŒøŒargs¯ØŒ db_encode_blob’øŒ0 db_encode_blob€íXˆ›°xaparamsŸX	locationýûðñû‚p˜T‘p21¼È ð*D:\Inetpub\wwwroot\ISHome\includes\backtrace.phpð˜pRˆÎþ/,Ž¨ÀaD:\Inetpub\wwwroot\ISHome\includes\db_odbc.phpþ  Ž@&null‎ÀŽpassæ ŽàŽnullêÀŽèconnîà themeҏ€ŽÙÀp€ÜH˜myErrorHandler	ÃpŽ/D:\Inetpub\wwwroot\ISHome\includes\db_odbc.php	ÊpWEBDEV4P1(… ¨hSpŸ‚|„(SpŸ‚|Є('(PýûðñûpŸ‚|8…)B<)<pŸ‚|ð„ )>*PPa©H…hSpŸ‚|ب,?pŸ‚|,PýûðñûpŸ‚|©-B<-<pŸ‚|€->->.sP ëÀÀ=Ã0 H…s"È¨db_num_rowsect) ¨è¨rs-Ȩ©è¨ˆ’rsPØ…ø…hSpŸ‚|€…0?-pŸ‚|0PýûðñûpŸ‚|è…1B
Sponsor our Newsletter | Privacy Policy | Terms of Service