Lỗi php khó hiểu (đã sửa được)

$actived_date = date('Y-m-d\TH:i:sP', strtotime($article['actived_date']));
            $element = '<?xml version="1.0" encoding="UTF-8"?>
            <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
                <url id="'.$article["id"].'">
                <loc>https://hotavn.ga/'.$article["friendly"].'_'.$article["id"].'.html</loc>
                <lastmod>'.$actived_date.'</lastmod>
                <changefreq>always</changefreq>
                <priority>0.8</priority>
                </url>
            </urlset>';
            $render = new DOMDocument();
            $render->validateOnParse = true;
            $render->loadXML($element);
            $element = $render->getElementsByTagName('url'); 
            $element = $dom->importNode($element[0], true);
            $parent->item(0)->appendChild($element); 
            $parent->item(0)->appendChild($dom->createTextNode("\n"));
            $dom->save($xml_src);

Mình có code như trên, khi mình up lên máy chủ, máy chủ liên tục báo lỗi 500. và mình tra ra thì thấy nếu bỏ 2 dòng
$parent->item(0)->appendChild($element); $parent->item(0)->appendChild($dom->createTextNode("\n"));
thì code hoạt động, bạn nào giúp mình với nhé

Bạn phải bật lỗi lên để xem xem là lỗi gì, chứ đừng để cái 500 error đấy nó làm rối.

1 Like

Nhìn sơ thì không thấy cái thằng $parent được sinh ra ở đâu, bạn có chắc là nó hợp lệ

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?