PDA

View Full Version : Please help with PHP dilemma


paulprice85
04-27-2010, 12:47 PM
Hi all,

I have some php code in my document to feed a blog from blogger.com to a site. I have inserted the php code (see attached) but it does not work. Some of the text near the end of the php text is black like it serves no function so it then appears at text on the site (eg in design view). So its clear its not working properly, can anyone see where I'm going wrong?

Thanks for your help

Corrosive
04-27-2010, 12:58 PM
Hi Paul

Please keep PHP posts in the PHP board. It makes it easier for others to search the forum. Thanks

davidj
04-27-2010, 03:37 PM
where you have...

echo '<div id="rssbox">
<ul>' $count = 0;......

Try this

echo '<div id="rssbox">
<ul>'; //<<< note the terminator

$count = 0;

The reason why the syntax colouring could be misreporting an error is that the simplexml_load_string is creating an object and your code editor can not reference this syntax

paulprice85
04-27-2010, 10:22 PM
Just tried that and it is not working. and it is from that point in the code it is showing up on design view. Any other ideas?

Thanks

edbr
04-28-2010, 02:19 AM
and it is from that point in the code it is showing up on design view
piost the code as you have it now in code tags here please

paulprice85
04-28-2010, 03:48 AM
<?php
$cache_time = 3600*24; // 24 hours

$cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/test.rss';
$timedif = @(time() - filemtime($cache_file));

if (file_exists($cache_file) && $timedif < $cache_time) {
$string = file_get_contents($cache_file);
} else {
$string = file_get_contents('http://www.web-development-blog.com/feed/');
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $string, strlen($string));
fclose($f);
}
}
$xml = simplexml_load_string($string);

// place the code below somewhere in your html
echo '
<div id="rssbox">
<ul>';
$count = 0;
$max = 3;
// the next object is an example for a feed from wordpress
foreach ($xml->channel->item as $val) {
if ($count < $max) {
echo '
<li>
<strong>'.$val->title.'</strong><br />
'.$val->description.' | <a href="'.$val->link.'">More &gt;</a>
</li>';
}
$count++;
}
echo '
</ul>
</div>';
?>

paulprice85
04-28-2010, 03:53 AM
it looks like its working here so why on my site is a lot of the text near the bottom black like its inactive?

Is there something else I should be putting it within? I understand I just stick it in wherever I want the blog to appear. At the moment the code is inside

<td><p align="center">

paulprice85
04-28-2010, 05:09 AM
I'll type out now exactly what I'm doing so you can point out where I'm going wrong. This is the first time I've played with php so I dont know if what I'm doing is right or wrong.

1. I open my html dreamweaver document where I want to show this blog feed
2. I place the above code in where I want it to appear on the page
3. I edit the '$string = file_get_contents' to my blog address
4. I select save as and change the .html extension to .php
5. I preview the page in my browser and there is no blog there and the bottom third of the code literally shows up on the page preview

Where am I going wrong?

edbr
04-28-2010, 05:12 AM
as you say this part id ok so it maybe with your page layout. to be honest i dont work with tables except on emails so im very rusty but if you try this code between body tags for example no pron . try withought the align="center" though im grasping here a bit

tux
04-28-2010, 05:50 AM
I have just created a tested page and added your code to it.

When I run the page I get this which I take to be the blog feed.

-----------------------------------------------------------------

PHP Mail Scripts using SMTP transport, a guide for beginners
PHP has a very simple mail function which is used very often for basic text mail messages. What if you need to attach files or if you need to send your e-mail messages via SMTP? Than itís time to use a more advanced script. This is because the standard mail function has only limited standard [...] | More >
Create surveys with Google Forms
These days I needed an online tool to create a customer survey. Google Docs has a form feature which I tried this time and I was very surprised how easy and powerful this function is. Using Google forms, you donít need any knowledge about how a web based form works. In this article we will [...] | More >
Win a free ticket for the DIBI Web Conference 2010
We hold a ďsmallĒ contest within the next edition of our finalwebsites.com newsletter. As a friend of the DIBI Web Conference 2010, we got one free ticket (value £199) and we like give this ticket to one of our subscribers. If youíre not a member yet, subscribe here. We will provide more information
within the [...] | More >

------------------------------------------------------------------


Therefore it must be something in your code that is wrong. Post all of your code for the page that you are trying to include this in.

paulprice85
04-28-2010, 05:54 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>hoopingrocks.com</title>
<style type="text/css">

body{
margin:0;
padding:0;
line-height: 1.5em;
}

b{font-size: 110%;}
em{color: red;}


#maincontainer{
width: 980px; /*Width of main container*/
margin: 0 auto; /*Center container on page*/
color:#000000;
}

#topsection{
background: #666666;
height: 180px; /*Height of top section*/
}

#topsection h1{
margin: 0;
padding-top: 15px;
color:#0000FF;
padding-left: 15px;
}

#contentwrapper{
float: left;
width: 100%;
background-color:#000000;
}

#contentcolumn{
margin-left: 0px;
color:#000000;
text-align: center;
font-family: Andale Mono, monospace;
font-size:18px;
font-style:italic;
}

#leftcolumn{
float: left;
width: 0px; /*Width of left column*/
margin-left: -980px; /*Set left margin to -(MainContainerWidth)*/
background: #C8FC98;
}



#paralinks

{color:#FFFFFF;}

a:link {color: #FFFFFF;} /* unvisited link */
a:visited {color:#FFFFFF;} /* visited link */
a:hover {color: #FF00CC;} /* mouse over link */
a:active {color:#0000FF;} /* selected link */

a:link {text-decoration:underline;}
a:visited {text-decoration:underline;}
a:hover {text-decoration:underline;}
a:active {text-decoration:underline:}

a:link {font-size: 90%;}
a:visited {font-size: 90%;}
a:hover {font-size: 90%;}
a:active {font-size: 90%;}


#rssbox {font:"Courier New", Courier, monospace;}
#rssbox ul {styles here}
#rssbox ul li {styles here}
#rssbox a:link {styles here}
#rssbox a:visited {styles here}
#rssbox a:hover {styles here}
#rssbox a:active {styles here}


#footer
{font-family: Gill Sans, sans-serif;
clear: left;
width: 100%;
background: #666666;
color: #FFF;
text-align: center;
padding: 4px 0;}

a:link {color: #FFFFFF;} /* unvisited link */
a:visited {color:#FFFFFF;} /* visited link */
a:hover {color: #FF00CC;} /* mouse over link */
a:active {color:#0000FF;} /* selected link */

a:link {text-decoration:none;} /* removes underline */
a:visited {text-decoration:none;}
a:hover {text-decoration:none;}
a:active {text-decoration:none;}

a:link {font-size: 90%;}
a:visited {font-size: 90%;}
a:hover {font-size: 90%;}
a:active {font-size: 90%;}


.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
color:#FFFFFF;
padding-top:10px;
}


</style>




</head>
<body>
<div id="maincontainer">

<div id="topsection"><div class="innertube">
<table width="900" border="0">
<tr>
<td width="213" height="152"><img src="Untitled-5.png" alt="HR" width="180" height="150" /></td>
<td width="677"><img src="BOAH.png" width="500" height="60" align="top" /></td>
</tr>
</table>
<h1>&nbsp;</h1>
</div></div>

<div id="contentwrapper">
<div id="contentcolumn">
<div id="paralinks">
<p>"I am currently travelling in Australia so no hoop classes until further notice.<br />
My new website is now under construction. In the meantime please visit <a href="http://www.hooping.org/">hooping.org</a>, <a href="http://www.hoopcity.ca/">hoopcity.ca</a> and <a href="http://www.rainbow-hoops.com/">rainbow-hoops.com</a> Happy Hooping!" </p>
<table width="700" border="0" align="center">
<tr>



<?php
$cache_time = 3600*24; // 24 hours

$cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/test.rss';
$timedif = @(time() - filemtime($cache_file));

if (file_exists($cache_file) && $timedif < $cache_time) {
$string = file_get_contents($cache_file);
} else {
$string = file_get_contents('http://www.web-development-blog.com/feed/');
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $string, strlen($string));
fclose($f);
}
}
$xml = simplexml_load_string($string);

// place the code below somewhere in your html
echo '
<div id="rssbox">
<ul>';
$count = 0;
$max = 3;
// the next object is an example for a feed from wordpress
foreach ($xml->channel->item as $val) {
if ($count < $max) {
echo '
<li>
<strong>'.$val->title.'</strong><br />
'.$val->description.' | <a href="'.$val->link.'">More &gt;</a>
</li>';
}
$count++;
}
echo '
</ul>
</div>';
?>





</tr>
</table>
</p>
</div>
</div>
</div>

<div id="footer"> <a href="http://www.aboutpaul.co.uk">Site currently being designed by aboutpaul.co.uk</a></div>
</div>
</body>
</html>

paulprice85
04-28-2010, 05:55 AM
There's the code above, seen as I have php in the document should it be .html or .php? Although I've tried both and get the same problem.

edbr
04-28-2010, 06:28 AM
this works . i took out the tables though i couldnt help myself. has to be .php or your server will not process it

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>hoopingrocks.com</title>
<style type="text/css">

body{
margin:0;
padding:0;
line-height: 1.5em;
}

b{font-size: 110%;}
em{color: red;}


#maincontainer{
width: 980px; /*Width of main container*/
margin: 0 auto; /*Center container on page*/
color:#000000;
}

#topsection{
background: #666666;
height: 180px; /*Height of top section*/
}

#topsection h1{
margin: 0;
padding-top: 15px;
color:#0000FF;
padding-left: 15px;
}

#contentwrapper{
float: left;
width: 100%;
background-color:#000000;
}

#contentcolumn{
margin-left: 0px;
color:#000000;
text-align: center;
font-family: Andale Mono, monospace;
font-size:18px;
font-style:italic;
}

#leftcolumn{
float: left;
width: 0px; /*Width of left column*/
margin-left: -980px; /*Set left margin to -(MainContainerWidth)*/
background: #C8FC98;
}



#paralinks

{color:#FFFFFF;}

a:link {color: #FFFFFF;} /* unvisited link */
a:visited {color:#FFFFFF;} /* visited link */
a:hover {color: #FF00CC;} /* mouse over link */
a:active {color:#0000FF;} /* selected link */

a:link {text-decoration:underline;}
a:visited {text-decoration:underline;}
a:hover {text-decoration:underline;}
a:active {text-decoration:underline:}

a:link {font-size: 90%;}
a:visited {font-size: 90%;}
a:hover {font-size: 90%;}
a:active {font-size: 90%;}


#rssbox {font:"Courier New", Courier, monospace;}
#rssbox ul {styles here}
#rssbox ul li {styles here}
#rssbox a:link {styles here}
#rssbox a:visited {styles here}
#rssbox a:hover {styles here}
#rssbox a:active {styles here}


#footer
{font-family: Gill Sans, sans-serif;
clear: left;
width: 100%;
background: #666666;
color: #FFF;
text-align: center;
padding: 4px 0;}

a:link {color: #FFFFFF;} /* unvisited link */
a:visited {color:#FFFFFF;} /* visited link */
a:hover {color: #FF00CC;} /* mouse over link */
a:active {color:#0000FF;} /* selected link */

a:link {text-decoration:none;} /* removes underline */
a:visited {text-decoration:none;}
a:hover {text-decoration:none;}
a:active {text-decoration:none;}

a:link {font-size: 90%;}
a:visited {font-size: 90%;}
a:hover {font-size: 90%;}
a:active {font-size: 90%;}


.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
color:#FFFFFF;
padding-top:10px;
}


</style>




</head>
<body>
<div id="maincontainer">

<div id="topsection"><div class="innertube">
<img src="Untitled-5.png" alt="HR" width="180" height="150" /></td>
<<img src="BOAH.png" width="500" height="60" align="top" />
<h1>&nbsp;</h1>
</div></div>

<div id="contentwrapper">
<div id="contentcolumn">
<div id="paralinks">
<p>"I am currently travelling in Australia so no hoop classes until further notice.<br />
My new website is now under construction. In the meantime please visit <a href="http://www.hooping.org/">hooping.org</a>, <a href="http://www.hoopcity.ca/">hoopcity.ca</a> and <a href="http://www.rainbow-hoops.com/">rainbow-hoops.com</a> Happy Hooping!" </p>




<?php
$cache_time = 3600*24; // 24 hours

$cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/test.rss';
$timedif = @(time() - filemtime($cache_file));

if (file_exists($cache_file) && $timedif < $cache_time) {
$string = file_get_contents($cache_file);
} else {
$string = file_get_contents('http://www.web-development-blog.com/feed/');
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $string, strlen($string));
fclose($f);
}
}
$xml = simplexml_load_string($string);

// place the code below somewhere in your html
echo '
<div id="rssbox">
<ul>';
$count = 0;
$max = 3;
// the next object is an example for a feed from wordpress
foreach ($xml->channel->item as $val) {
if ($count < $max) {
echo '
<li>
<strong>'.$val->title.'</strong><br />
'.$val->description.' | <a href="'.$val->link.'">More &gt;</a>
</li>';
}
$count++;
}
echo '
</ul>
</div>';
?>






</p>
</div>
</div>
</div>

<div id="footer"> <a href="http://www.aboutpaul.co.uk">Site currently being designed by aboutpaul.co.uk</a></div>
</div>
</body>
</html>

paulprice85
04-28-2010, 06:40 AM
Thanks for doing that, I copied what you posted above and its still not working and I've previewed in different browsers. Do you think theres a setting somewhere that is not allowing this to work? I cant get my head around it. I take it that it doesent need to be 'live' online for it to work?

edbr
04-28-2010, 06:43 AM
are you uploading this too a server?

paulprice85
04-28-2010, 06:51 AM
no I'm trying to preview straight from dreamweaver locally on this computer. Does it need to be uploaded to an online server to see any effect at all?

edbr
04-28-2010, 06:53 AM
yes its the server that will process the php so it wont work with out. this works on my localserver so if you upload ot a server with php you will be good to go

paulprice85
04-28-2010, 07:00 AM
thanks man I cant believe the answer is that simple!

paulprice85
04-28-2010, 07:52 AM
I just uploaded the page as a .php which is linked from hoopingrocks.com

But the problem now is the page is showing up blank ie. no feed. but when I type http://pipkorea.blogspot.com/feeds/posts/default into my browser, the blog is there.

Any ideas why its not feeding the blog through?

edbr
04-28-2010, 08:36 AM
whats the link to the page you uploaded

paulprice85
04-28-2010, 08:40 AM
http://www.hoopingrocks.com/blog.php

edbr
04-28-2010, 08:52 AM
these warnings
Result: 0 errors / 5 warnings

line 153 column 1 - Warning: <div> isn't allowed in <tr> elements
line 148 column 5 - Info: <tr> previously mentioned
line 161 column 5 - Warning: missing <td>
line 163 column 3 - Warning: inserting implicit <p>
line 154 column 5 - Warning: trimming empty <ul>
line 163 column 3 - Warning: trimming empty <p>


try uploading the code i gave with out the table to eliminate this being an html problem. your server is an apache server with php so this shopuld work

edbr
04-28-2010, 09:04 AM
in fact check here http://jobsearch-indonesia.com/hoop.php

paulprice85
04-28-2010, 09:07 AM
is that working then? I changed the code from mine to yours and uploaded and all seems the same. Is it the same when you visit?

edbr
04-28-2010, 09:10 AM
it works on the above server server using the code i posted for you

paulprice85
04-28-2010, 09:17 AM
thanks for that. Ill need to contact the server then to ask why it isn't working. Sorry if this has been tedious, as you can tell im new to this :-S

edbr
04-28-2010, 09:18 AM
right i just uploaded it to another server and got errors because of server security, a more strict server

file_get_contents() [function.file-get-contents (http://concord-bali-villas.com/function.file-get-contents)]: URL file-access is disabled in the server configuration

maybe it is a server problem but is not reporting errors .

concord-bali-villas.com/hoop.php
if anyone wants to add their 2 cents, ill leave both files uploaded for today
the anyone in particular being davidj of course