Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Coding a Source Code Viewer
Old 10-18-2007, 04:12 PM Coding a Source Code Viewer
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Alright, I've come across something that I'm having trouble with. I'm -attempting- to create a "Source Code Viewer". Now I googled one, and found it, yet I'm having some trouble making sense of it.

PHP Code:
function getDirList ($dirName) {
$d dir($dirName);
while(
$entry $d->read()) {
if (
$entry != "." && $entry != "..") {
if (
is_dir($dirName."/".$entry)) {
getDirList($dirName."/".$entry);
} else {
if (
    (
ereg('\.php$'$entry))
    && 
    (!
ereg('index\.php$'$entry))
){    
echo 
"<a href=./?filename=".$dirName."/".$entry.">".$dirName."/".$entry."</a><br>\n";

If you wouldn't mind, i want to ensure that I'm understanding the various portions of this script. For the first line: "function getDirList ($dirName) {" That would typically, in english, be: "Get Directory List called 'dirName'"

Following that, the second line pertains to setting $d to the directory name. However, I don't understand the third line. I know the "while" function, but the $entry = $d->read()) { I dont understand. Any clarification would be appreciated.
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-18-2007, 04:21 PM Re: Coding a Source Code Viewer
Foundationflash's Avatar
Ultra Talker

Posts: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
The while statement runs continuously through $dir reading more and more until it cannot. For each iteration, $entry is that bit that it has just read.
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 10-18-2007, 09:01 PM Re: Coding a Source Code Viewer
MGT-Evelath's Avatar
Average Talker

Posts: 21
Trades: 0
Ok; I'm getting started on it, perhaps you could give me some assistance with it:

"Source.php"
PHP Code:
<?

getFiles
();
showSource();
showEdit();
showLog();
?>
From there I attempt to gather the needed files that I would need:

PHP Code:
function getFiles()
{
   
//get list of all the files for use in the other routines

global $dirPtr$theFiles;
chdir(".");
$dirPtr openDir(".");
$currentFile readDir($dirPtr);
while (
$currentFile !== false)
{
   
$theFiles $currentFile;
   
$currentFile readDir($dirPtr);
}  
//End While

}  // End Getting Files 
Is this correct thus far? The Challenge is as follows:

"Create a source code viewers. Given the filename, the program should read in the file and convery each instance of < into &lt;. Save this new file to another name. this allows you to show your source code to others."

I've attempted asking others, however many can't really assist. And this as far as I've gotten. Any help?
MGT-Evelath is offline
Reply With Quote
View Public Profile
 
Old 10-20-2007, 06:46 AM Re: Coding a Source Code Viewer
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
after reading the task here are some pieces of code :

Code:
function get_file_contents($filename){
  $handle = fopen($filename, "rb");
  $contents = htmlspecialchars(fread($handle, filesize($filename)));
  fclose($handle);
}
Code:
function list_files($dir){
if (is_dir($dir)) {
   if ($dh = opendir($dir)) {
       while (($file = readdir($dh)) !== false) {
          if ($file!='.' && $file!='..') {
            $files[]= $dir . $file;
          } // de la if ...
       }
       closedir($dh);
   }
}

if (is_array($files)) {return $files; } else {return false;}

}// de la functie ..
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by solomongaby; 10-20-2007 at 06:48 AM..
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Reply     « Reply to Coding a Source Code Viewer
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13440 seconds with 12 queries