Jump to content

php script that reads from .txt file.(solved)


lurah

Recommended Posts

Hi all.
This is my first "real" php script and it surely looks like it  ::) It works ok except with windows IE browser as far as i have received information from members of site.
Im not sure is it up to my code or how IE works. Some advices would be nice  ::)

FILE: links.php
[code]
/*
links.php
main file on our Related Links page.

virtanen.kristian@ascii-world.com
PUBLIC DOMAIN 2006

*/
?>
<html>
<head>
<title>ASCII-World - Related Links</title>
<style >
a      { margin-top:      0px;
margin-bottom:  10px;
font-family:    Arial, Verdana;
font-size:      small;
font-weight:    bolder }

a:link    { margin-top:      0px;
margin-bottom:  0px;
margin-left:    0px;
color:          #FFFFDD;
text-decoration: none }
a:visited  { margin-top:      0px;
margin-bottom:  0px;
margin-left:    0px;
color:          #FFFFDD;
text-decoration: none }
a:active  { margin-top:      0px;
margin-bottom:  0px;
margin-left:    0px;
color:          #FFFFDD;
text-decoration: underline }
a:hover    { margin-top:      0px;
margin-bottom:  0px;
margin-left:    0px;
color:          #FFFFFF;
text-decoration: underline }
</style>
</head>

<body bgcolor="#606060">
<center>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td align="left" bgcolor="#606060" width="100%" colspan="2" class="header"><font face="Arial" size="2" color="#FFFFFF"><b>INTRODUCTION:</b><br><br></font> </td>
</tr>

<tr>
<td width="50%" colspan="2" bgcolor="#606060" >
<p align="justify">
<font face="Arial" size="2" color="#FFFFBB">
<b>The ASCII-World related links is where you can find other websites that have relevant information or projects.<br>
They could be other websites boosting the ASCII effort, ASCII projects in the making,<br>
Text Games of all kinds, you name it we'll do our best to have it here available for you.</b>
</p>
</td>
</tr>

</tbody>
</table>
</center> 

<table align="center" cellpadding="0" cellspacing="0" border="0" width="80%">
<tr>
<td align="left" bgcolor="#606060" width="50%" colspan="2" class="header">
<form action="links.php" method="post">
<select name="category">
<option value="">Select category</option>
<?php include"select_catagories.php"; ?>
</select>
<input type="submit" value="Show links">
</form>
</td>
</tr>
</table>


<?php

// selected category
$cat_file = $_POST['category'];

// let's open selected link list file
$handle = @fopen("links_db/".$cat_file, "r");

// file handling/reading
if ($handle)
{
while (!feof($handle)) // file reading loop start
{
$address = fgets($handle, 4096); // first line is URL
$site = fgets($handle, 4096); // secons line is name of site
$desc = fgets($handle, 4096); // third is description
     
if ($address != "") // if there is anything to output
{
echo "<li><b>"; // font, size and colors. <li> too
echo "<a href=\"".$address."\" target=\"Blank\" >".$site."</a></b><br>"; // we spit our link out on screen
echo "<font face=\"Arial\" size=\"2\" color=\"#FFFFBB\">".$desc."</li><br><br></font>"; // let's not forget description
} // end of (if $address) checking
} // file reading loop end
fclose($handle); // close file
}
?>
</body>
</html>[/code]

FILE: select_categories.php
[code]
<?php
/*
select_catagories.php
this file reads current catagories from file links_db/catagories.txt
and adds em on select area.

virtanen.kristian@ascii-world.com
PUBLIC DOMAIN 2006

*/

// we open our category "database"
$handle = @fopen("links_db/categories.txt", "r");
if ($handle) {
  while (!feof($handle)) {
      $cat_name = fgets($handle, 4096);      // name of category  IE:(ASCII Art Websites)
      $cat_file = fgets($handle, 4096);      // name of it's link's list.  ASCII Art Websites = 1.txt
     
      // and let's spit it on our select box
      echo "<option value=\"".$cat_file."\">".$cat_name."</option>";
  }
}
?>[/code]

Example of categories.txt
[code]ASCII Art Websites
1.txt
ASCII tools and generators
2.txt
General ASCII Websites
3.txt [/code]

and link txt files (1.txt)
[code]http://homepage.ntlworld.com/palmer666/
David Palmer's site
ASCII Art and comics by David Palmer.
http://www.heartnsoul.com/ascii_art/ascii_objects.htm
ASCII Art Gallery - objects
So much pictures, you gona need a day to see em all.  [/code]

You can find this from www.ascii-world.com -> Related Links
And whole "package" can be downloaded from http://www.adaworld.com/asciiworld/links/links.tar.gz
Link to comment
Share on other sites

Have you validated your HTML?  Very often errors are handled differently by different browsers, leading to different behaviour.  Even with valid HTML, you can get different behaviour.

ACtually I see some invalid HTML already.  A table is structured into rows, like this:

[code]<table> <tr> <td> </td> <td> </td> </tr> </table>[/code]

A td can only exist inside a tr.  Both browsers should be able to handle that fine though, so i doubt it's the problem.
Link to comment
Share on other sites

Hi.

I doubt it's up to select_catagories.php. I have to specify this. IE users can see and use select box, but they cant see link list created after button press.

So i doubt, problem is on this one [code] echo "<font face=\"Arial\" size=\"2\" color=\"#FFFFBB\"><li>"; // font, size and colors. <li> too
echo "<b><a href=\"".$address."\" target=\"Blank\" >".$site."</a></b><br></li>"; // we spit our link out on screen
echo $desc."<br><br></font>"; // let's not forget description
} // end of (if $address) checking[/code]
Link to comment
Share on other sites

Is your PHP configured to display errors?  If it's not and you have a script error somewhere chances are no output may even be making it to the browser.

When you view the page in the browser, look at the HTML source the browser received and see where it ended.  That may help.
Link to comment
Share on other sites

Ok, this one is solved. [code] $cat_name = fgets($handle, 4096); // name of category  IE:(ASCII Art Websites)
$cat_name = str_replace(array("\r", "\n"), "", $cat_name); // EOL marks out of there
$cat_file = fgets($handle, 4096); // name of it's link's list. ASCII Art Websites = 1.txt
$cat_file = str_replace(array("\r", "\n"), "", $cat_file); // EOL marks out of there
[/code]

End of line marks readed from .txt files were the messy ones. Thanks all for helping me.
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.