gomesla Posted September 10, 2008 Share Posted September 10, 2008 I'm trying to create a class that gives me a XML list of my objects but when I call the function it does not display the breaks or anything in between the "<" None of the /t or /n tags work. Any idea why? class XmlProductWriter extends ShopProductWriter { public function write() { $str = "<products>\n"; foreach ( $this->products as $shopProduct ) { $str .= "\t<product title=\"{$shopProduct->getTitle()}\">\n"; $str .= "\t\t<summary>\n"; $str .= "\t\t{$shopProduct->getProducer()}\n"; $str .= "\t\t</summary>\n"; $str .= "\t</product>\n"; } $str .= "</products>\n"; print $str; } } Link to comment https://forums.phpfreaks.com/topic/123650-n-or-t-wont-work/ Share on other sites More sharing options...
sasa Posted September 10, 2008 Share Posted September 10, 2008 are you look page source code or browser window? Link to comment https://forums.phpfreaks.com/topic/123650-n-or-t-wont-work/#findComment-638526 Share on other sites More sharing options...
wildteen88 Posted September 10, 2008 Share Posted September 10, 2008 Are you displaying the generated XML directly in the browser within an HTML page? If so web browsers do not display any form of whitespace characters (other than a single space) on the page. In order for a browser to display a new line within the page you need to use the line break tag (<br />). Link to comment https://forums.phpfreaks.com/topic/123650-n-or-t-wont-work/#findComment-638528 Share on other sites More sharing options...
thebadbad Posted September 10, 2008 Share Posted September 10, 2008 If you want to display it in the browser, you can use htmlentities() and then print_r() it inside some pre tags. <?php $data = "<xml>\n\t<test></test>\n</xml>"; echo '<pre>', print_r(htmlentities($data), true), '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/123650-n-or-t-wont-work/#findComment-638537 Share on other sites More sharing options...
Mchl Posted September 10, 2008 Share Posted September 10, 2008 I think that just making it a valid XML file will make browsers display it as such (apply default XSL) Link to comment https://forums.phpfreaks.com/topic/123650-n-or-t-wont-work/#findComment-638539 Share on other sites More sharing options...
thebadbad Posted September 10, 2008 Share Posted September 10, 2008 I think that just making it a valid XML file will make browsers display it as such (apply default XSL) If you serve it as XML through PHP, that is. <?php header('Content-type: application/xml'); //print data ?> Link to comment https://forums.phpfreaks.com/topic/123650-n-or-t-wont-work/#findComment-638597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.