unexpected T_CONSTANT_ENCAPSED_STRING

Generating a RSS feed by modifying this code: http://www.webreference.com/authoring/languages/xml/rss/custom_feeds/index.html

However I am receiving the following error:

XML Parsing Error: syntax error

Location: http://websitename/rss/index.php
Line Number 2, Column 1:Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /path/rss/classes/RSS.class.php on line 46
^

My code is:

[code]<?php
class RSS
{
public function RSS()
{
require_once (’…/dbAccess.php’);
}
public function GetFeed()
{
return $this->getDetails() . $this->getItems();
}
private function dbConnect()
{
DEFINE (‘LINK’, mysql_connect (HOST, USER, PASSWORD));
}
private function getDetails()
{
$detailsTable = “Table1”;
$this->dbConnect($detailsTable);
$query = "SELECT * FROM ". $detailsTable;
$result = mysql_db_query (DB, $query, LINK);
while($row = mysql_fetch_array($result))
{
$details = ’<?xml version="1.0" encoding="ISO-8859-1" ?>


‘. $row[‘type’] .’
‘. $row[‘weekdate’] .’
‘. $row[‘r’] .’
‘. $row[‘start’] .’
‘. $row[‘end’] .’
‘. $row[‘average’] .’
‘. $row[‘frequent’] .’
}
return $details;
}
private function getItems()
{
$itemsTable = “Table2”;
$this->dbConnect($itemsTable);
$query = "SELECT * FROM ". $itemsTable;
$result = mysql_db_query (DB, $query, LINK);
$items = ‘’;
while($row = mysql_fetch_array($result))
{
$items .= ’
‘. $row[‘type’] .’
‘. $row[‘weekdate’] .’
‘. $row[‘r’] .’
‘. $row[‘start’] .’
‘. $row[‘end’] .’
‘. $row[‘average’] .’
‘. $row[‘frequent’] .’
';
}

        $items .= '</channel> 
                </rss>'; 
        return $items; 
    } 
} 
?> [/code]

Can you advise why this is happening?

Can you show us the code in this file

/path/rss/classes/RSS.class.php

Hello,

The code which was posted is from RSS.class.php

index.php contains:

[code]<?
header(“Content-Type: application/xml; charset=ISO-8859-1”);

error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
include(“classes/RSS.class.php”);
$rss = new RSS();
echo $rss->GetFeed();
?> [/code]

Just a guess…

Change:

[php] $items .= ’
‘. $row[‘type’] .’
‘. $row[‘weekdate’] .’
‘. $row[‘r’] .’
‘. $row[‘start’] .’
‘. $row[‘end’] .’
‘. $row[‘average’] .’
‘. $row[‘frequent’] .’
';[/php]

TO:

[php] $items .= “”. $row[‘type’] ."". $row[‘weekdate’] ."
“. $row[‘r’] .”". $row[‘start’] ."
“. $row[‘end’] .”". $row[‘average’] ."
“. $row[‘frequent’] .”";[/php]

OP’s code is a mess of escaping and is just asking for trouble. Just enclose the variables in curly braces and forget the mass escaping. The opening and closing quotes of the line must be double quotes to interpolate the variables.

Instead of
‘. $row[‘average’] .’

Do this

{$row[‘average’]}

I figured it out…

Change this:

[php] $details = ’<?xml version="1.0" encoding="ISO-8859-1" ?>


‘. $row[‘type’] .’
‘. $row[‘weekdate’] .’
‘. $row[‘r’] .’
‘. $row[‘start’] .’
‘. $row[‘end’] .’
‘. $row[‘average’] .’
‘. $row[‘frequent’] .’ [/php]

To

[php] $details = ’<?xml version="1.0" encoding="ISO-8859-1" ?>


‘. $row[‘type’] .’
‘. $row[‘weekdate’] .’
‘. $row[‘r’] .’
‘. $row[‘start’] .’
‘. $row[‘end’] .’
‘. $row[‘average’] .’
‘. $row[‘frequent’] .’’; [/php]

You forgot the ending ';

Hello,

That worked, thanks.

A note that mysql_db_query is deprecated.

Sponsor our Newsletter | Privacy Policy | Terms of Service