homepage Welcome to WebmasterWorld Guest from 54.234.228.64
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
PHP Code Interpretation
Inherited website with professional php code
Matoca




msg:4134540
 7:25 am on May 18, 2010 (gmt 0)

I inherited a website 6 months ago with bits of php code on most pages. I have been studying lynda.com, W3C and books and I am beginning to understand more, but at a advanced beginner level. I use Dreamweaver CS4 and have been able to work around any code I don't understand (mostly because it is still working!). Any time it gets in my way, I comment it out and do the same thing with html.

I would like to be able to take some of the more complex code and really understand what it is doing. I can pick out php terms and I understand them quite well, but sometimes putting it all together doesn't make it very clear. I can figure out the general idea of what is happening, but not the specifics. How long does this take someone who is self study to learn?

I have a php code script that basically looks at all the files in a directory, figures out how big they are, assigns them MB, KB etc using php math and then echoes all the file names, along with these file types and sizes (ex: This Is The File Name (PDF 47 KB)) on the page. I cannot understand how the php defines how files are ordered when placed on the page. I want more control over the alphabetical (or in order of date) display of these files. They just seem to go into the directory and pop up randomly in the list.

Is there somewhere on the internet where I can paste php code and have it partially interpreted step by step? Or is there somewhere where people post snippets of php code that do similar functions?
Thanks for your help

 

lavazza




msg:4134553
 8:09 am on May 18, 2010 (gmt 0)

Hi Matoca, and welcome :)

Is there somewhere on the internet where I can paste php code and have it partially interpreted step by step?
Yes, there are many places, and I reckon one the bestest ever places is right here on WebmasterWorld :)

See the PHP Server Side Scripting sub-forum [webmasterworld.com]

Before posting any code, read the PHP Forum Charter [webmasterworld.com], which inclides the Posting Guidelines for the PHP Server Side Scripting Forum and has a link to Troubleshooting 101 revisited: How much code should I post? [webmasterworld.com]

rocknbil




msg:4134782
 5:05 pm on May 18, 2010 (gmt 0)

I want more control over the alphabetical (or in order of date) display of these files.


Here's a good start: sort() [us.php.net]

Of course that only works when you store the file names in an array, but there are many server commands you can access with exec() or system(). That is, for example, you are on a Linux server, you could use the Linux command ls inside exec() to get the directory list. Depending on which flags you use, you can order the results of ls in different ways.

Matoca




msg:4135090
 3:56 am on May 19, 2010 (gmt 0)

Thank you for the quick responses! I have moved over to the PHP Server Side Scripting sub-forum for more help.

I checked out the sort() at us.php.net and was very delighted to find so many possibilities. Something in there may be able to help me. The items that are going into this directory are pdf's for a company that hosts a private site for investors. So stuff like forms, reports etc. I want some semblance of organization (so alphabetical is good) but dumping them all in there like that tends to hide new additions to the group. I know the company wants to draw attention to newer items and doesn't understand why they end up buried in the list. Up until now, I have had no clue what is happening and was reluctant to mess it up. So I guess now my job is to figure out how to do both of these requests together: by date into the server and then alphabetically after that first sort. Or maybe just number them? Wonder if the sort sees numbers as an alphabetical order?

rocknbil




msg:4135503
 7:04 pm on May 19, 2010 (gmt 0)

I believe it does, yes, and if you look at the flags you can specify them if it's not behaving as you'd expect:

<?php
header("Content-type:text/html");
$fwd = $bkwd = Array('bodacious','horrendous','xanadu','pineapple');
sort($fwd);
rsort($bkwd);
echo "Forward:<br>\n";
foreach ($fwd as $word) { echo "$word<br>\n"; }
echo "<br>Backward:<br>\n";
foreach ($bkwd as $word) { echo "$word<br>\n"; }
?>

outputs

Forward:
bodacious
horrendous
pineapple
xanadu

Backward:
xanadu
pineapple
horrendous
bodacious

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved