Please help with a php syntax error

Status
Not open for further replies.

WallaceCleaver

New member
Jun 26, 2006
598
0
0
My computer chair
I am trying to run a page with php in it and I am getting this message:

Parse error: syntax error, unexpected T_VARIABLE on line 7

Can anyone tell me what exactly a T_VARIABLE is so that I know what I am looking for while trying to fix this?
 


There could be a number of reasons that you get an syntax error like this. Most likely just forgot a } or ; or something simple. Any chance of posting the code around line 7 which might give a better idea of the problem.
 
I'm not a big php developer however you probably need to add a ; after
$rss = new lastRSS

Try that first and post if it still not working.
 
That had an effect, but only in that another error appeared. You gotta love php, huh? The new error is: Warning: Invalid argument supplied for foreach() on line 10

Here is the complete code is someone could please sort out the problem.

<?php
include './lastRSS.php';
$rss = new lastRSS;
$rss->cache_dir = './cache';
$rss->cache_time = 3600;
if ($rs = $rss->get('URL GOES HERE')) {
foreach ($s['items'] as $item) {
echo "<h2>$item[title]</h2>$item[descripition]";
}
if ($rs['items_count'] <= 0) {
echo "Sorry, no items found. <br /><br />";
}} else {
die ('Error: RSS file not found....');
}
?>
 
Ok, I just found the problem, but now something curious has happened. I'm not getting any errors, but I am getting a blank screen. I tried this with another rss feed parser and got a blank screen with that one too. I know that the above code works with this feed because I have talked to someone who has used it. Any ideas? Could it be some setting on my server?
 
Code:
if ($rs = $rss->get('URL GOES HERE')) {
foreach ($s['items'] as $item) {
    echo "<h2>$item[title]</h2>$item[descripition]";
}

This is the part of the code that echo's the values back to the browser. Are you sure that the $s variable isn't supposed to be $rs on

foreach ($s['items'] as $item) {
 
Here is the update. Rembrandt was right. I found that error just after I posted the code with the mistake. Even with the correction it just displays a blank white page. If I try a different feed it will display, but no dice with this one. As I said, however, this other guy can get it to show up, so I am wondering if it is a server issue.

<?php
include './lastRSS.php';
$rss = new lastRSS;
$rss->cache_dir = './cache';
$rss->cache_time = 3600;
if ($rs = $rss->get('URL GOES HERE')) {
foreach ($rs['items'] as $item) {
echo "<h2>$item[title]</h2>$item[descripition]";
}
if ($rs['items_count'] <= 0) {
echo "Sorry, no items found. <br /><br />";
}} else {
die ('Error: RSS file not found....');
}
?>

Haha, yes pjleonhardt I am. I may not know a lot about php, but I know that. :)
 
WallaceCleaver said:
Here is the update. Rembrandt was right. I found that error just after I posted the code with the mistake. Even with the correction it just displays a blank white page. If I try a different feed it will display, but no dice with this one. As I said, however, this other guy can get it to show up, so I am wondering if it is a server issue.

So this other guy can get the feed you want no probs but you can't using the same code? It could be a server issue but I doubt it considering that you can see other feeds ok. Maybe it's the structure of the RSS feed and the code your using needs some minor mods.
 
I think this line might be your problem:

WallaceCleaver said:
echo "<h2>$item[title]</h2>$item[descripition]";

Try putting 'title' and 'description' in quotes. I'm guessing $item is a hash, so you have to pass it a string to do the hash on. I don't know PHP that well, but all your other strings have quotes on 'em. Try this:

echo "<h2>$item['title']</h2>$item['descripition']";

Please also note that in your code, 'description' is misspelled as 'descripition'. If you end up only seeing the titles, that's why.
 
Yes, rembrandt that is exactly what is happening. Numbat, if I add quotes then I get this error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 11

I fixed the typo in the spelling of description, but I still can't get that specific feed to show up. As I said other feeds will appear. I sent a message to the guy who got this to work, but I haven't heard back yet. Hopefully he will be able to help.
 
Ok - give this a shot then:

echo "<h2>" . $item['title'] . "</h2>" . $item['description'];

May or may not make a difference - it looks like PHP's smart enough to decode it as a string whether or not it's in quotes, but it's worth a shot.
 
if you
print_r($item);
instead of the echo it will show you exactly what is contained in that variable.
Make sure there's something there before trying anything else.

Good luck.
 
Here are the results of your suggestions. Numbat, when I tried yours I got this error:

Parse error: syntax error, unexpected '"', expecting ',' or ';' on line 11

scoby, yours resulted in this:

Array ( [title] => [link] => [description] => [pubDate] => Wed, 12 Jul 2006 6:56:51 )

I don't know exactly what that proves, but it proves something. The guy that has gotten this to work said that he had to get is web host to enable url_fopen. Since I don't know a whole lot about php that meant nothing to me, but I wrote to my web host and asked for it to be enabled. They wrote back and said that I can upload a custom php.ini file.

I just did some research and url_fopen is on, so now I am totally stumped.
 
The plot thickens. That guy who was helping me with this ran the script on his server and it worked. I have now contacted my hosting company in the hope that they will be of some help, but I'm not getting my hopes up.
 
scoby, yours resulted in this:

Array ( [title] => [link] => [description] => [pubDate] => Wed, 12 Jul 2006 6:56:51 )

That means that the $item variable has keys for information [title], [link] and [description] but that there's no information being stored for those keys.

[pubDate] is the only one with a value ( shown after the => symbol ) and that's
Wed, 12 Jul 2006 6:56:51

url_fopen allows you to request a file on another server and then work on it a sa file
In this case you're getting an rss file.

try this:
PHP:
<?php
include './lastRSS.php';
$rss = new lastRSS;
$rss->cache_dir = './cache';
$rss->cache_time = 3600;
if ($rs = $rss->get('URL GOES HERE')) {

print_r($rs);

foreach ($rs['items'] as $item) {
echo "<h2>$item[title]</h2>$item[descripition]";
}
if ($rs['items_count'] <= 0) {
echo "Sorry, no items found. <br /><br />";
}} else {
die ('Error: RSS file not found....');
}
?>
this will show exactly what is held in the variable when you try to retrieve the rss file.
It looks like you are getting something but not in the format you expected maybe?

Stanley asked what library you are using. Did you download a script or write your own in order to do the $rss->get();?
if you got it on the net tell us where or is it one that the other guy wrote?

another thing, can you get the file to display in your browser? it loads ok? can you share the url and the lastRSS.php file. I could try it and see what happens for me.

We'll figure it out.
 
Status
Not open for further replies.