fionafenton
asked on
Inserting carriage returns in xml text
I'm using PHP to query an MySql database and produce an xml file for another site.
I'm concating 3 of the database fields into one xml tag but want to add a carriage return between them. What should I be using?
$xmltext = $field1. "carriage return here".$field2. "carriage return here".$field3;
$xmltext = htmlspecialchars($xmltext) ;
$xmltext = addslashes($xmltext);
$_xml .="<Description>".urlencod e($xmltext )."</Descr iption>\r" ;
I'm concating 3 of the database fields into one xml tag but want to add a carriage return between them. What should I be using?
$xmltext = $field1. "carriage return here".$field2. "carriage return here".$field3;
$xmltext = htmlspecialchars($xmltext)
$xmltext = addslashes($xmltext);
$_xml .="<Description>".urlencod
ASKER
No, I want to know what to use for a carriage return so that it displays correctly when inserted into an xml tag.
I've tried <br>, 
,
 and but they display exactly as written when displayed on the final web page.
i.e.
text from field 1. text from field 2. text from field3.
Rather than
text from field 1.
text from field 2.
text from field 3.
I've tried <br>, 
,
 and but they display exactly as written when displayed on the final web page.
i.e.
text from field 1. text from field 2. text from field3.
Rather than
text from field 1.
text from field 2.
text from field 3.
Than stop using this:
And start using htmlentities() and html_entity_decode
http://www.php.net/manual/en/function.htmlentities.php
http://php.net/manual/en/function.html-entity-decode.php
$xmltext = htmlspecialchars($xmltext);
$xmltext = addslashes($xmltext);
And start using htmlentities() and html_entity_decode
http://www.php.net/manual/en/function.htmlentities.php
http://php.net/manual/en/function.html-entity-decode.php
ASKER
I have no control over what happens to the data at the other end, so html-entity-decode is irrelevant.
If I use <br> as the carriage turn it shouldn't make any difference whether I use htmlspecialchars or htemlentities. However, when I use <br> it is displayed as that in the browser.
I'm sure it's to do with the way the other website (which I'm feeding into) handles the data. I think I need a non html way of inserting a carriage return. I have also tried /n and /r but these don't work either.
If I use <br> as the carriage turn it shouldn't make any difference whether I use htmlspecialchars or htemlentities. However, when I use <br> it is displayed as that in the browser.
I'm sure it's to do with the way the other website (which I'm feeding into) handles the data. I think I need a non html way of inserting a carriage return. I have also tried /n and /r but these don't work either.
If you don't have control over the other website and the other website does not 'decode' your encoded data than this is impossible.
ASKER
I found the solution myself through trial and error.
I needed to use %0a and not urlencode it.
My code is now like this
$xmltext = $field1. "carriage return here".$field2. "carriage return here".$field3;
$xmltext = htmlspecialchars($xmltext) ;
$xmltext = addslashes($xmltext);
$_xml .="<Description>".urlencod e(addslash es(htmlspe cialchars( $field1))) ."%0A".url encode(add slashes(ht mlspecialc hars($fiel d2)))."%0A ".urlencod e(addslash es(htmlspe cialchars( $field3))) ."%0A"."</ Descriptio n>\r";
I needed to use %0a and not urlencode it.
My code is now like this
$xmltext = $field1. "carriage return here".$field2. "carriage return here".$field3;
$xmltext = htmlspecialchars($xmltext)
$xmltext = addslashes($xmltext);
$_xml .="<Description>".urlencod
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found solution myself
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws
Open in new window
Or do you need some advice on what sign to use as seperator?
In that case i would just use something then never will be used in the field texts.
My suggestion is just a semicolon (;) but i'm not aware of your data.