SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Indianapolis, IN
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Everything After -> Not Getting Parsed

    I am trying to run a Simplepie script on my site. I am running on a server with php 4.4.7 and Simplepie Compatibility test shows my server will work.

    When I use their example code (posted below) it works as a standalone page.

    When I try to cut that code up put it into an existing page, it parses everything except whatever falls after the -> (code below).

    Is there something I am missing?


    Here is the stand alone example page they have
    Code:
    <?php
     
    // Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
    require_once('php/simplepie.inc');
     
    // We'll process this feed with all of the default options.
    $feed = new SimplePie('http://simplepie.org/blog/feed/');
     
    // This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
    $feed->handle_content_type();
     
    // Let's begin our XHTML webpage code.  The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag.
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    	<title>Sample SimplePie Page</title>
    	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
     
    	<style type="text/css">
    	body {
    		font:12px/1.4em Verdana, sans-serif;
    		color:#333;
    		background-color:#fff;
    		width:700px;
    		margin:50px auto;
    		padding:0;
    	}
     
    	a {
    		color:#326EA1;
    		text-decoration:underline;
    		padding:0 1px;
    	}
     
    	a:hover {
    		background-color:#333;
    		color:#fff;
    		text-decoration:none;
    	}
     
    	div.header {
    		border-bottom:1px solid #999;
    	}
     
    	div.item {
    		padding:5px 0;
    		border-bottom:1px solid #999;
    	}
    	</style>
     
    </head>
    <body>
     <h1>Feed</h1>
    	<div class="header">
    		<h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
    		<p><?php echo $feed->get_description(); ?></p>
    	</div>
     
    	<?php
    	/*
    	Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
    	*/
    	foreach ($feed->get_items() as $item):
    	?>
     
    		<div class="item">
    			<h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
    			<p><?php echo $item->get_description(); ?></p>
    			<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
    		</div>
     
    	<?php endforeach; ?>
     
    </body>
    </html>

    Here is what I pulled out and placed into the HEAD tags of my page

    Code:
    <?php
    
    require_once('php/simplepie.inc');
    
    $feed = new SimplePie('http://simplepie.org/blog/feed/');
    
    $feed->handle_content_type();
     
    ?>

    and here is what I used in the BODY

    Code:
    <h1>Feed</h1>
    	<div class="header">
    		<h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
    		<p><?php echo $feed->get_description(); ?></p>
    	</div>
     
    	<?php
    	/*
    	Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
    	*/
    	foreach ($feed->get_items() as $item):
    	?>
     
    		<div class="item">
    			<h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
    			<p><?php echo $item->get_description(); ?></p>
    			<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
    		</div>
     
    	<?php endforeach; ?>
    To me, everything looks to be fine; however in the body, the following things are showing on the actual web page:

    Feed
    get_title(); ?>

    get_description(); ?>
    get_items() as $item): ?>
    get_title(); ?>

    get_description(); ?>

    Posted on get_date('j F Y | g:i a'); ?>



    It should also be noted that Dreamweaver's code view also shows this as a problem (those lines are colored black when the page is saved as both an html page and a php page).

    Thanks for your help.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right click > view html source. all your php code should be there. this means php is not parsing it.

    You generally need to name the file with a .php file extension, and request the url through a webserver which has php installed and configured properly.

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Are you sure the PHP is parsing the file? Does this file have the PHP extension?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Indianapolis, IN
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured out the problem....

    It is a corporate site with a corporate template built for the Lowest Common Denominator. So our offices in the small cities don't need a web team to maintain them. Those that are lucky enough to have a web team run into a restrictive environment where it is hard to work with the template to do anything even mildly advanced.

    In this case, I have access to a file where I can add code to the head tags indirectly. Everything I put up there is parsed. In the body, on the other hand, the home page is parsed first, then the updates I add to the site via their admin section is all client side, therefore not parsed.

    So I will need to look to Javascript to pull in a simple RSS Feed to the home page...

    So the long and short of it... I thank you for your help, everything is done right, except the body stuff will never be parsed and you are correct.

    I apologize for wasting your time.

    Thanks,


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •