Jump to content


Photo

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


  • Please log in to reply
9 replies to this topic

#1 lurah

lurah
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 September 2006 - 09:33 AM

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
/*
 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>

FILE: select_categories.php
<?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>";
   }
}
?>

Example of categories.txt
ASCII Art Websites
1.txt
ASCII tools and generators
2.txt
General ASCII Websites
3.txt

and link txt files (1.txt)
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. 

You can find this from www.ascii-world.com -> Related Links
And whole "package" can be downloaded from http://www.adaworld....ks/links.tar.gz

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 13 September 2006 - 01:40 PM

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:

<table> <tr> <td> </td> <td> </td> </tr> </table>

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.

#3 lurah

lurah
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 September 2006 - 03:38 PM

Thanks for tips btherl.
I fixed <td><tr> issue. Alltho it didnt help as you assumed. Got to keep on wondering.

#4 jrodd32

jrodd32
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 13 September 2006 - 03:57 PM

you might want to try saving the select_catagories.php file as an .inc file and changing your include statements as necessary

#5 lurah

lurah
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 September 2006 - 04:40 PM

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
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


#6 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 13 September 2006 - 05:40 PM

You should not be ending your head section before starting your styles code
<head><title>ASCII-World - Related Links</title></head>
	<style >
place the
</head>
just before the
<body>


#7 lurah

lurah
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 September 2006 - 06:22 PM

Thanks mainewoods for tip.
I fixed more html part of source. I pasted it on first post of thread.
Still IE dont echo nothing. Im totally out of ideas how to solve this one.

#8 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 13 September 2006 - 06:51 PM

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.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#9 lurah

lurah
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 September 2006 - 08:22 PM

Ok, after testing result is this. Script works fine with older IE versions. IE 7 wont work.
So i guess it's IE issue then. Well, never liked MS anyway lol. But would be nice to get it working with IE.

#10 lurah

lurah
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 13 September 2006 - 08:46 PM

Ok, this one is solved.
$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

End of line marks readed from .txt files were the messy ones. Thanks all for helping me.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users