mercredi 15 novembre 2017

Laravel parsing data to xml, giving error on some characters

I have a laravel project where people can see a list of restaurants, create orders and stuff.

I'm now working on SEO and I've created my website sitemap, all is fine, but there's data with characters like and they giving me error when I load the xml page

& ; , < ' > "

i don't know what else, how can I handle this ? PS: I can not replace characters, because I need to submit to google the real names and titles.

I have a controller where I'm getting the data :

    public function index()
    {
      $articles = Article::all()->first();

      return response()->view('sitemap.index', [
          'articles' => $articles ])
         ->header('Content-Type', 'text/xml');
    }
   public function articles()
    {
        $articles = Article::latest()->get();
        return response()->view('sitemap.articles', [
            'articles' => $articles,
        ])->header('Content-Type', 'text/xml');
    }

sitemap.xml :

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

 <sitemapindex xmlns="http://ift.tt/xwbjRF">
<sitemap>
    <loc>http://ift.tt/2AIDxyh;
</sitemap>

sitemap/articles :

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://ift.tt/xwbjRF">
    @foreach ($articles as $article)
        <url>
            <loc>http://ift.tt/2ii9maf</loc>
            <lastmod></lastmod>
            <changefreq>weekly</changefreq>
            <priority>0.9</priority>
        </url>
    @endforeach
</urlset>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zCB5MS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire