
1 abelyao 2014 年 12 月 10 日 sitemap.xml 竟然是 1W 条记录全出来… 我猜测吧,可能是其中某条的转义符问题?你应该是循环拼接的吧,在循环里加个 echo $row; 看看是拼到第几条记录开始有问题的 |
2 hdjdcyl 2014 年 12 月 10 日 xml没玩过,是不是碰到html代码解析了,你在浏览器查看源代码看一下。 |
3 iyaozhen 2014 年 12 月 10 日 “用PHP拼接字符串。用于生成网站的sitemap.xml。” 找个php操纵DOM的库方便点吧。 |
4 yangqi 2014 年 12 月 10 日 error_reporting(E_ALL); |
5 kofj 2014 年 12 月 10 日 via Android 没用框架或者模板引擎裸奔的?为什么不用模板呢?写好模板,数据往里面一扔,搞定,实测20w数据xml没有压力。如果非要要看警告信息,error_reporting调整为notice就好了。 |
6 philway 2014 年 12 月 10 日 应该是有编码不同的字符输出,仔细再检查一下吧。 |
7 lincanbin 2014 年 12 月 11 日 直接显示空白我猜是你浏览器挂了。 |
8 wormcy 2014 年 12 月 11 日 via Android 看下源代码可能有惊喜 |
9 huigeer 2014 年 12 月 11 日 直接命令行生成xml, 打开报错, 一下子就能找到原因, |
11 feiyuanqiu 2014 年 12 月 11 日 不要自己拼XML! PHP有很多方法来处理XML,自己拼是最不推荐的方法 1、生成 XML 可以用 DOMDocument : ```php // create a new document $dom = new DOMDocument('1.0'); // create root element. and append it to the document $book = $dom->appendChild($dom->createElement('book')); // create the child element and append it to the book $title = $book->appendChild($dom->createElement('title')); // set the text and cover attribute for $title $tilte->appendChild($dom->createTextNode('title_name')); $title->setAttribute('edition', 3); // format the document, and print it $dom->formatOutput = true; $xml = $dom->saveXML(); ``` 2、解析基本XML文档可以用 SimpleXML : ```php // 从文件中加载xml文档 $sx = simplexml_load_file(__DIR__ . '/test.xml'); // 从字符串中加载 $sx = simplexml_load_string($xml); foreach($sx->person as $person) { $first_name = $person->firstname; $last_name = $person->lastname; } ``` 3、解析复杂 XML 可以用 DOM : ```php $node = dom_import_simplexml(simplexml_load_string($xml)); ``` 4、解析大型 XML 文档可以用 XMLReader : ```php $reader = new XMLReader; // load from file $reader->open(__DIR__ . '/test.xml'); // load from variable // $reader->XML($xml); // loop through document while ($reader->read()) { // if in a element named 'author' if ($reader->nodeType == XMLREADER::ELEMENT && $reader->localName == 'author') { // move to the next node; $reader->read(); print $reader->value . "\n"; } } ``` 另外,浏览器是会解析XML的,当你的XML是错误的时候,浏览器解析不了就不会显示出来。 这时候你可以直接查看网页源代码或者在 echo 的时候前面加个 <pre> |
12 feiyuanqiu 2014 年 12 月 11 日 上一条说的 echo 前面加 <pre> 是我记错了,刚才看了下以前的代码,应该用 header 浏览器就知道该怎么显示 XML 了: header('Content-Type: text/xml'); |
13 tczzjin 2014 年 12 月 11 日 php的内存爆了? |