Jump to content

Issues writing HTML using a PHP file


Rawns

Recommended Posts

Ive noticed that if I carry on making an indivdule page for each part of my site, Ill have to change the 'Latest News' bullets on each page! I cant be arsed with this so I have had the idea to make a simple PHP file which will print HTML out allowing me to only change the one file instead of every page.

Im having issues though as im not that good with PHP.

in my main page where I want the code headlines to be shown, Ive added this code:

[code]    
<?php
include ("news.php");
?>
[/code]

This should point to the news.php file if i'm right.

In the news file, I've got this code:

[code]
<?php
<?php
print"Blog now online! <a href="#blog">full story...</a>";
print"RSS News feed avaiable! <a href="#rss">full story...</a>";
print"Guestbook &amp; Forums go live! <a href="#forum">full story...</a>";
print"Site Launch!<a href="#launch"> full story...</a>";
?>
[/code]

Ive added it to my site and uploaded it all but nothing is displayed. Have I forgot something in the news.php file?

Any help would be most appreciated!
Link to comment
Share on other sites

You ahve a problem because you havent escaped the quotes in the print. The server thinks that after <a href= the print is closed.
This will work:

<?php
print"Blog now online! <a href=\"#blog\">full story...</a>";
print"RSS News feed avaiable! <a href=\"#rss\">full story...</a>";
print"Guestbook &amp; Forums go live! <a href=\"#forum\">full story...</a>";
print"Site Launch!<a href=\"#launch\"> full story...</a>";
?>

Orio.
Link to comment
Share on other sites

The problem is becuase you are not escaping your quotes. As you are starting your print statement with a double quote ( " ) mark. PHp will stop the printing your text when it finds another occurance of a double quote.

Now in order for PHP to not stop when it finds another double quote you will need to escape it, which means adding a forward slash infront of the quote like so: [b]\"[/b] however your last ending quote shouldn't be escaped though.

So what I'm saying is this if you start of with a double quote, you should escape any doubles quotes within the string like so:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]print "Site Launch!<a href=[!--coloro:red--][span style=\"color:red\"][!--/coloro--][b]\"[/b][!--colorc--][/span][!--/colorc--]#launch[!--coloro:red--][span style=\"color:red\"][!--/coloro--][b]\"[/b][!--colorc--][/span][!--/colorc--]> full story...</a>";[/quote]
Link to comment
Share on other sites

This should work:
[code]<?php
print"Blog now online! <a href=\"#blog\">full story...</a>";
print"RSS News feed avaiable! <a href=\"#rss\">full story...</a>";
print"Guestbook &amp; Forums go live! <a href=\"#forum\">full story...</a>";
print"Site Launch!<a href=\"#launch\"> full story...</a>";
?>[/code]

Also as its just html there is noneed to use the print statement at all just do this:
[code]Blog now online! <a href="#blog">full story...</a>
RSS News feed avaiable! <a href="#rss">full story...</a>
Guestbook &amp; Forums go live! <a href="#forum">full story...</a>
Site Launch!<a href="#launch"> full story...</a>[/code]
Link to comment
Share on other sites

[!--quoteo(post=369171:date=Apr 27 2006, 12:27 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 27 2006, 12:27 PM) [snapback]369171[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Also as its just html there is noneed to use the print statement at all just do this:
[code]Blog now online! <a href="#blog">full story...</a>
RSS News feed avaiable! <a href="#rss">full story...</a>
Guestbook &amp; Forums go live! <a href="#forum">full story...</a>
Site Launch!<a href="#launch"> full story...</a>[/code]
[/quote]

Sorry to seem stupid but this is new to me, I take it i include that code within the <?php ?> tags?

Still does not work :(
Link to comment
Share on other sites

The most simplest way of doing this is to have each php file set up like this:
[code]<?php
//Any php stuff be done here
?>
<html>
<head>
  <title>my page title</title>
</head>
<body>
  blah blah blah
  more html
  and some more
  <?php include("news.php"); ?>
</body>
</html>[/code]
That way all your HTML can be written as normal. All you have to do is add one line (in above example, its near the bottom) to include into the script one file called "news.php"
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.