Archive

Archive for the ‘PHP’ Category

Anther php script

May 12, 2011 Leave a comment

I have a site at www.gagi.zxq.net where I post my Java applets. Zymic.com offers free hosting, and so I set up a small site there for showing the applets I build. Since there is no database support for free hosting, I have not built any script for running my site, but I only transfer files via ftp.

However, since the number of my applets will inevitably increase, I figured I need to either acquire database support, or find a way around. I decided that I need to find a way around to build a mechanism using PHP, without any database.

My simple plan is as follows:

I need a directory that will hold the html files that reference java classes.

I need another directory that holds my java classes.

With a PHP script, I access the folder where my html files reside, and for each file in the folder, I generate a link on my index page to the html file.

However, a problem appeared along the way; the script would generate two links too many. The first link leading to the folder where the PHP file resides, and the second link leading to the folder that contains the folder where the PHP file resides. For the script and the modification, read the code in a jpeg file because wordpress won’t let me post php code:
null

Categories: PHP

empty post

November 10, 2010 Leave a comment
Categories: PHP, Uncategorized

A quick PHP script

November 3, 2010 Leave a comment

A couple of days ago, hearing someone talk about a certain book I got curious and decided to read that book. I found that book online saved on a txt file and discovered that it is hard to read as lines extend way longer than my desktop alows to be seen and that there too many clear rows on the text file. This made my reading the book unpleasent and postponed reading it like four days – until I decided to use PHP to my rescue (not that I was in any jeopardy, anyways).

What I did is this: I saved the book on another text file to remove the lines that I did not want. Then, I read the text in the file using the php function file(). Note that this function reads the text as an array, each line being an element in the array. As a result, I knew I had an array that either contained lines with text or blank lines.

With a foreach() statement I saved the previous array on another array named $new. This was only necessary if I was to write the content into another file. However, once in the $new array, I made the text echo in a web page with another foreach() statement, and now I have my book in a more pleasant appearance on a web page, reading it.

Now the code, which you are free to use if you want to, redistribute, or whatever:

<?php

$new[0] = ”;
$i = 0;
$file = file(‘Thebook.txt’);
echo “size of array = “.sizeof($file).”<br>”;
foreach($file as $line){
if($line == ”){}else{
$new[$i] = $line. “</br>”;
$i++;
}
}

foreach($new as $a){
echo $a;

}
?>

Categories: PHP, Uncategorized