Jul 25, 2008

Php Installed Modules Dynamic Reference Tool - An effective tool for coding in PHP

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Php Installed Modules Dynamic Reference Tool - An effective tool for coding in PHP

SystemWisdom
PHP Installed Modules Dynamic Reference Tool

A dynamic tool for referencing PHP modules and their associated routines, which are installed on your web-server.

**Note: Uses only 2 functions built-in to PHPs core and should be easy to convert to a later version of PHP. This current version uses PHP4.


Example:
PHP Installed Modules Dynamic Reference Tool


Abstract:
    [/tab]As a PHP Developer, it is nice to know what functionality is available to you, and what you would have to implement yourself. Some of this functionality is provided for you by the PHP core, of which I am sure most of you are familiar with. However, a lot more may be added via Extension Modules installed with the PHP Web-Server (usually installed by your web-server administrator). Once these modules are installed, they provide a rich library of functions for your PHP scripts to access, giving you more flexibility and control as a developer.

[tab]The trick is in knowing what modules are installed with PHP on your web-server, what functionality those modules provide, and how to use that functionality in your scripts. All of this can be provided in the Dynamic Reference Tool we will create in this tutorial, which utilizes PHPs vast Online Documentation with its simple referencing standard!

By Rob J. Secord, B.Sc. (SystemWisdom)



Intended Audience:
Beginner to Advanced PHP Web-Application Developers.

Assumed knowledge:
-- PHP Basics
-- Arrays
-- HTML


Theory:
    [/tab]Built-in to PHP are 2 functions that will assist us in creating our Dynamic Reference Tool, and they are: get_loaded_extensions() and get_extension_funcs(). These 2 functions are the heart of this tutorial and the Dynamic Reference Tool, and are rather simplistic to use!

[tab]Furthermore, we have the Official Online Documentation provided by PHP at php.net. The beauty lies within the simple referencing standard they provide, which is a URL in the format php.net/function_name_here. And considering they provide documentation for nearly every published PHP Module, this is a good thing! biggrin.gif

    [/tab]We will start by using the get_loaded_extensions() function, which returns to us an array of all the module names loaded with your web-servers installation of PHP. Using this array, we will build an HTML table to display all of the installed modules. We will then pass the module-name to the get_extension_funcs() function which will return to us an array of all of the function names contained within the module we specify. Again, we will build an HTML table to display all of the Module Functions. Finally, we will link each Module Function to PHPs Online Documentation for quick & easy reference!


Implementation:
[tab]We will start off by making our PHP file which we will call 'php_modules.php', you may call it anything you like. Once completed, you will place this file on your PHP web-server and run it as you would run any other PHP page. In page we will lay down a simple HTML/CSS framework to work from. It should look something like the following, refering to it any time during the next section:
CODE

<html>
<head>

<style><!--

body  { color:#426394; }
table { border: 1px solid #426394; }

td.Seperator
{   border: solid #426394;
   border-width: 0px 0px 1px 0px;
}

td.Text, a, a:hover
{   padding: 0px 5px 0px 5px;
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-weight: normal;
   font-style: normal;
   font-size: 8pt;
   color: #426394;
}

a:hover
{   background-color: #E3E3E3;
}

//--></style>

</head>
<body>

</body></html>


    [/tab]You will notice a very basic HTML structure, with some simple CSS styles added to give some appeal to our page. If you don't know CSS you can safely omit the CSS completely by removing both 'style' tags and everything in between.

[tab]Moving on, we will now begin adding our PHP code to our page. First we need to think about the layout; one table will hold all of the module names, and for each module name there will be an associated table holding all of the function names (Please view my example posted near the top of this tutorial for a visual indication).

    [/tab]If you will notice in my example, the Modules Table at the very top has 5 columns, and each table underneath has only 4 columns. This is a personal choice as I feel it looks more appealing, though it may be easily changed in your own scripts. The point to notice is that the PHP script itself only deals with 2 table structures; the 5 column one and the 4 column one (which is repeated). We will hold these values in 2 constant variables, so that they may be easily changed in the future:
CODE

<?php
$table1_cols = 5;
$table2_cols = 4;
?>


[tab]We will also need to create 2 Arrays to hold our lists of Modules and Functions, so we create those immediately as well:
CODE

<?php
$aModules = array();
$aModuleFuncs = array();
?>


    [/tab]Now before going any further, I would like to first show you the completed code chunk which builds our Modules Table, and then we will walk through it together as I explain each step. Please have a good look at the following:
CODE

$counter = 1;
echo "<br><br><font size=+1><b><u>Listed Modules</u></b>:</font><br><br>\n";
echo "<table border=0 cellpadding=0 cellspacing=0 width=100%>";

$aModules = get_loaded_extensions();
foreach( $aModules as $szModuleName )
{
   // Check for First Column
   if( $counter == 1 ) echo "\n <tr>";

   // Output Column Data
   echo "\n  <td class=Text><a href=\"#$szModuleName\">$szModuleName</a></td>";

   // Check for Last Column
   if( $counter == $table1_cols )
   {
       echo "\n </tr>";
       $counter = 0;
   }
   $counter++;
}
echo "\n</table>\n\n";


[tab]The first line from above is a 'counter' variable to keep track of which column we are currently outputting. This helps us determine when to output an opening table row tag (<tr>) and its corresponding closing tag (</tr>). The next 2 lines simply output a title "Listed Modules" and open the Table tag (<table>) with some default attributes.

    [/tab]The 4th line from above is where we call the get_loaded_extensions() function which then returns to us an array populated with the names of all loaded modules. We store the array in our variable created from above named 'aModules'. Now that we have our array, it is a simple matter of outputting each value it contains via PHPs foreach loop.

[tab]So next we have our foreach() loop which I am sure you are all familiar with. We take each value in the array and assign it to the variable 'szModuleName' which we use to output the module name to HTML.

    [/tab]Using the 'counter' variable mentioned earlier we will track which column we are currently outputting to; if it is the first column then we need to start by outputting an opening table row tag (<tr>) as in:
CODE

   if( $counter == 1 ) echo "\n <tr>";


[tab]Next we get to output the actual module name, which we enclose in Table Data tags (<td>) with a style-class of 'Text' as defined by our CSS at the top. We will also want to link each Module Name with its respective Functions Table somewhere below the Modules Table, so we again enclose the actual module name with an Anchor Tag (<a>) which will be linked to a named-anchor (using the # symbol) elsewhere in our page. We will keep the name of the named-anchor the same as the module name for simplicity. This can all be seen in the following line of the code:
CODE

echo "\n  <td class=Text><a href=\"#$szModuleName\">$szModuleName</a></td>";


    [/tab]Next we will want to check to see if we are outputting to the last column, and if so, we simply output a closing Table Row tag (</tr>) to finish our current row, and reset the counter to 0 to generate a new row in our next pass of the foreach loop. After that, we are safe to increment the 'counter' variable by 1 in order to generate the next column of output. This can be seen in the following lines of code from above:
CODE

   if( $counter == $table1_cols )
   {
       echo "\n </tr>";
       $counter = 0;
   }
   $counter++;


[tab]Finally, to end the table after all of the module names have been output, we simply output a closing Table tag (</table>), as in:
CODE

echo "\n</table>\n\n";



    [/tab]Well, that is that for the Modules Table, but now we need to create a table for each module containing all of its respective functions. This can be achieved in the exact same way as with the table we just created above. However, this time we will need to generate the tables with 4 columns instead of 5, so we would use the constant variable 'table2_cols' we defined at the start when checking for the last column with our 'counter' variable. Also, we will need to wrap all of what we have just done into another loop which will output 1 table for each loaded module.

[tab]We begin by outputting another simple title "Module Functions":
CODE

echo "<br><br><font size=+1><b><u>Module Functions</u></b>:</font>\n<br><br>\n";


    [/tab]Then we go right back into another foreach() loop of all of the loaded modules, but this time we are not just outputting the module name, we are also passing the module name as a string to the second PHP function called get_extension_funcs() which will return an array of all of the function names within the module. But first we should output a title for the table indicating which module we are listing functions from. This will also server as a location for each named-anchor we are linking to from the Modules Table above. We simply create an Anchor tag (<a>) and give it a name equal to that of the module name. All of this can be seen in the following code, and is considerably straight-forward:
CODE

// Output Title
echo "<br><br><font size=+1><b><u>Module Functions</u></b>:</font>\n<br><br>\n";

// Modules Foreach Loop
foreach( $aModules as $szModuleName )
{
   echo "\n<table border=0 cellpadding=0 cellspacing=0 width=100%>";
   echo "\n <tr>\n  <td class=\"Text Seperator\" colspan=\"$table2_cols\"><a name=\"$szModuleName\">Functions in <b>$szModuleName</b> Module..</a></td>\n </tr>";

   // Loop through functions here..

   echo "\n</table>\n<br><br>\n\n";
}


[tab]As you can see from above, each module will have its own table of functions with a header indicating which module the functions belong to, as well as a named-anchor for use with the named-anchor-links we created in the Modules Table at the beginning. The comment line where I stated "Loop through functions here.." is the spot where we will duplicate our Modules Table code with minor alterations. Again, I will post the whole code chunk first, and explain the differences below (includes the code chunk listed directly above, with the comment line replaced):
CODE


echo "<br><br><font size=+1><b><u>Module Functions</u></b>:</font>\n<br><br>\n";

foreach( $aModules as $szModuleName )
{
   echo "\n<table border=0 cellpadding=0 cellspacing=0 width=100%>";
   echo "\n <tr>\n  <td class=\"Text Seperator\" colspan=\"$table2_cols\"><a name=\"$szModuleName\">Functions in <b>$szModuleName</b> Module..</a></td>\n </tr>";

   $counter = 1;
   $aModuleFuncs = get_extension_funcs( $szModuleName );
   foreach( $aModuleFuncs as $szFunctionName )
   {
       // Check for First Column
       if( $counter == 1 ) echo "\n <tr>";

       // Output Column Data
       echo "\n  <td class=Text><a href=\"http://php.net/$szFunctionName\" target=\"_new\">$szFunctionName</a></td>";

       // Check for Last Column
       if( $counter == $table2_cols )
       {
           echo "\n <tr>";
           $counter = 0;
       }
       $counter++;
   }

   echo "\n</table>\n<br><br>\n\n";
}


    [/tab]First thing to note is that the comment line has been replaced with a new code chunk that looks a lot like the very first foreach() loop we worked with. Again we have our 'counter' variable which servers the exact same purpose as before, but then we have our new function call to get_extension_funcs(). We pass the name of the current module, and it returns an array of function names, as in:
CODE

   $aModuleFuncs = get_extension_funcs( $szModuleName );


[tab]We then enter into our nested foreach loop where we will receive the name of each function in the module stored in the 'szFunctionName' variable. With this variable, we can then output the name of the function much like before. The only notable difference this time, is that we enclose the output function name with an Anchor tag (<a>) linking to PHPs Online Documentation! But that's not all, we can even use the function name in the URL of the link to point directly to the documentation on each specific function! All of this can be seen in the following code chunk (as also posted above):
CODE

   foreach( $aModuleFuncs as $szFunctionName )
   {
       // Check for First Column
       if( $counter == 1 ) echo "\n <tr>";

       // Output Column Data
       echo "\n  <td class=Text><a href=\"http://php.net/$szFunctionName\" target=\"_new\">$szFunctionName</a></td>";

       // Check for Last Column
       if( $counter == $table2_cols )
       {
           echo "\n <tr>";
           $counter = 0;
       }
       $counter++;
   }


    [/tab]After you have that, you have a working "PHP Installed Modules Dynamic Reference Tool" that you can use and re-use on any PHP web-servers you may be developing on! To put it all together, you should have the following:

Final Completed Source Code Example:
CODE

<html>
<head>
<style><!--
body
{   color:#426394;
}
table
{   border: 1px solid #426394;
}
td.Seperator
{   border: solid #426394;
   border-width: 0px 0px 1px 0px;
}
td.Text, a, a:hover
{   padding: 0px 5px 0px 5px;
   font-family: Verdana, Arial, Helvetica, sans-serif;
   font-weight: normal;
   font-style: normal;
   font-size: 8pt;
   color: #426394;
}
a:hover
{   background-color: #E3E3E3;
}
//--></style>
</head>
<body>

<?php

$table1_cols = 5;
$table2_cols = 4;

$aModules = array();
$aModuleFuncs = array();

$counter = 1;
echo "<br><br><font size=+1><b><u>Listed Modules</u></b>:</font><br><br>\n";
echo "<table border=0 cellpadding=0 cellspacing=0 width=100%>";

$aModules = get_loaded_extensions();
foreach( $aModules as $szModuleName )
{
   // Check for First Column
   if( $counter == 1 ) echo "\n <tr>";

   // Output Column Data
   echo "\n  <td class=Text><a href=\"#$szModuleName\" style=\"font-weight:bold;\">$szModuleName</a></td>";

   // Check for Last Column
   if( $counter == $table1_cols )
   {
       echo "\n </tr>";
       $counter = 0;
   }
   $counter++;
}
echo "\n</table>\n\n";

echo "<br><br><font size=+1><b><u>Module Functions</u></b>:</font>\n<br><br>\n";
//$aModules = get_loaded_extensions();
foreach( $aModules as $szModuleName )
{
   echo "\n<table border=0 cellpadding=0 cellspacing=0 width=100%>";
   echo "\n <tr>\n  <td class=\"Text Seperator\" colspan=\"$table2_cols\"><a name=\"$szModuleName\">Functions in <b>$szModuleName</b> Module..</a></td>\n </tr>";

   $counter = 1;
   $aModuleFuncs = get_extension_funcs( $szModuleName );
   foreach( $aModuleFuncs as $szFunctionName )
   {
       // Check for First Column
       if( $counter == 1 ) echo "\n <tr>";

       // Output Column Data
       echo "\n  <td class=Text><a href=\"http://php.net/$szFunctionName\" target=\"_new\">$szFunctionName</a></td>";

       // Check for Last Column
       if( $counter == $table2_cols )
       {
           echo "\n <tr>";
           $counter = 0;
       }
       $counter++;
   }
   echo "\n</table>\n<br><br>\n\n";
}

?>

</body></html>



Working Example:
PHP Installed Modules Dynamic Reference Tool


Conclusion:

[tab]Well, I hope that you have learned something useful from this tutorial, and maybe even use such a tool when developing your web-based applications in PHP! Remember, this tool uses only 2 built-in PHP functions and should be a very easy conversion to later versions of PHP.

    [/tab]Please feel free to comment on this tutorial, if you noticed anything wrong or out of place in this tutorial, please don't hesitate to mention it!

[tab]I am interested in all feedback really, I'm curious about what you think of my writing, tutorial, methods used, code, effectiveness, layout, etc.. Thanks!

 

 

 


Reply

HmmZ
Very nicely written tutorial. I do would like to mention that this is not a tutorial for beginners, although you explain things well. the scripting type used here is more advanced then a beginner would do, making it confusing for the beginning PHP-scripters.

Overal..great addition to the Trap17 tutorials! smile.gif

And for your great tutorials and dedication to Trap17 i have given you a rep point, keep up the great work mate!

Reply

rvalkass
This is an excellent and very useful tutorial. You have explained everything very well and make it very easy to understand. I have to agree with HmmZ however, that this is slightly too advanced for a coding beginner, but it is still a very good and well explained tutorial.

Reply

SystemWisdom
smile.gif Thx guys, I'm glad you liked it! I guess I am doing good at writing tutorials (even though I always used to hate writing essays in school), so I will have to keep it up! biggrin.gif

Though I guess it isn't really a tutorial for beginners like you both have said (as far as the code goes), but the tool alone would be a good tool for beginners still learning PHP, to know what functionality they have access to! wink.gif

So for anyone who only wants the tool (ignoring the tutorial), feel free to copy & paste the source code into your own PHP page, place it on your web-server, and away you go!


Reply

bjrn
Hey, this is really nice. Good job.

I don't think you have to worry about it not being for beginners. I mean, there are enough tutorials being posted for beginners here on Trap17 (which is a good thing), but it's nice when someone posts something more advanced as well.

I've played around with PHP some, but I'm hardly a guru, and I hadn't done anything with the get_loaded_extensions() function. And learning new things is always fun.

So thanks. smile.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php, installed, modules, dynamic, reference, tool, effective, tool, coding, php

  1. Nice Clean Php Layout Coding.
    Learn a nice neat way to code your layouts with php (7)
  2. Dynamic Signature - Yet Another Way To Do It
    Create dynamic sigs for multiple users using .htaccess and RewriteRule (0)
    Ever since I connected a program I made in Visual Basic to MySQL database, I had an idea to create
    some sort of a status page... And I did that, where I updated my connection status every 60 seconds,
    updated my Winamp playlist, and several other interesting things... Then, I figured I could create
    an image, and display all that info, and show it on forums, as a signature... And I made a great
    PHP script, that look real fancy, and does the job perfectly... So, I was adding the reference to
    http://status.galahad.trap17.com/stat.php to all the forums... BUT (there's ....
  3. Dynamic Signatures - The Real Way To Go
    Forget placing index.php in a signature.png folder. (8)
    This is only a very quick tutorial, meant to complement the dynamic signature tutorials that already
    exist here. It's nothing new, but it was just brought to my attention that not many people seem
    to be aware of this method. This does not cover the actual creation of dynamic signatures, per se -
    but rather a better 'trick' to allow you to use dynamic signatures on forums such as this
    one. I've noticed that most of the dynamic signature tutorials on this forum state that you
    must place a file index.php in a folder .png, in order to trick Invision Power....
  4. Image Gallery Tutorial Using Hoverbox
    A php solution to coding the Hoverbox Image Gallery (14)
    As reported in another posting , there is an Image Gallery named Hoverbox from the Sonspring site
    which is a pretty cool display method using CSS to have Thumbnail pictures double their size by
    hovering over them. I liked the css included in the original Tutorial as found on the Sonspring
    site , but I knew there was more than one use for the Hoverbox and took it upon myself to explore
    the use of the Hoverbox on a site I webmaster. One thing that wasn't right was having to
    hardcode the image tags, so the first version I wrote used php to fill the Hoverbox by rea....
  5. Making A Dynamic Page On Blogspot
    Using an external server to make your pages hosted on blogspot dynamic (5)
    Good morning everyone. Have you ever wondered how to allow your visitors to edit content on your
    blog? Like adding a post straight off the page, adding a link, editing your profile etc. This will
    be extremely useful if you want your visitors to contribute to your blog besides writing comments or
    tagging. 1. Adding a post straight off the page. Go to blogger.com, login, select your blog. Go to
    settings -> email. By enabling blog email, you can now add a post by simply sending an email to the
    address you specified. The address should look something like: yourusername....
  6. Templating System Using Php Includes
    Building a Dynamic site using Includes and flat-files. (13)
    Php based Templating System http://jlhaslip.trap17.com/template/index.php The Source Code
    for the scripts are included (literally) on the different pages on the Demo, including the Contact /
    Email script. The only page not there yet is the Message Script. Maybe tonight I will upload that.
    This one uses a little bit of query-string checking to confirm that the contents of the page are
    actually available (file_exists())and an allowed page content before serving it up. The
    'allowed page content' is done by checking against a flat-file containing an array....
  7. How To "lock Down" A Os X User Account
    Crude but effective way to maintain Macs (1)
    Here's a quick summary of how one can configure OS X for use in public labs running Panther
    (10.3). It should also work with Tiger (10.4) but I dunno. There may be better ways, but this is
    quick and cheap: 1. Install OS X fresh, or boot up your new Mac, and set the username to
    MacAdmin or the like. This is now the administrator account which users should never touch.
    Share this password only with trusted admins authorized to muck with critical systems. 2.
    Install all the software you expect anyone to need in the default folders (usually Applicat....
  8. Css And Javascript Combined For Dynamic Layout
    use of different CSS files at same site (9)
    This tutorial is meant for people that are dealing with problems while coding their site at 100% of
    width. Important notice: Some people has JavaScript disabled, so they will not be able to load CSS
    file (take this in account when creating your website). How this script works. In the HEAD of your
    HTML document will apply this command, so variable.js file will be load at start: CODE
    <script type="text/javascript" src="variable.js"></script> In
    browser JavaScript file variable.js is loaded. This Javascript file consist of this para....
  9. Php Dynamic Signatures
    Using the GD Module and MySQL (9)
    PHP Dynamic Signatures using the GD Module After much scowering on the internet to find a
    suitable tutorial on this subject, I came up empty-handed. So I was forced to learn it on my own
    through trial & error. And since I had discovered a lack of tutorials on this subject, I dediced to
    write one! Working Example: Abstract : Using the GD Module of PHP allows a
    developer to build custom Images with Dynamic Content. Such content could be the Requesting Users
    IP Address, Web-Browser Type, Operating System, even the number of times the user has see....
  10. Methods Of Optimizing Your Pc's Performance
    A sure and effective ways that works. (10)
    Methods of optimizing your PC for higher performance. 1st of all, let us start with my
    computer's hardware configuration. I am pasting the report generated by Lavalys' Everest
    Home Edition about my system. Note to Admins and Moderators: I pasted this report only to stress
    the effectivenes of the optimization methods and to proove to people that everything I am saying is
    true and not some fabricated story, but not for hosting credits purposes. The Report QUOTE  
      Computer                                          RIDHIMA (My personal computer, named aft....
  11. Transparent Scrollbars
    Coding Transparent Scrollbars (2)
    Why woud someone want a Transparent scrollbars you ask? Well fist of they do not cover too much of
    the image like the normal scrollbars. You can use transparent scrollbars for different kinds of web
    layouts such as popups, iframes, or scrolling div layers. For iframes, make sure you've inserted
    a background image for the table cell containing the iframe. You do not need to do that for
    scrolling div layers. Although, you cannot make the main scrollbar transparent unless you make it
    appear that way by selecting the same color for everything. After you code the scroll....
  12. Changing A Dynamic Ip
    How to change your dynamic IP. (18)
    In this tutorial I will tell you how to change a dynamic IP if you have Windows XP. First of all go
    to - Start >> Run - and type 'cmd'. A window with a black background and grey text. In
    this window type 'ipconfig' and text should come up saying: IP Address ............. *IP
    HERE* Subnet Mask ................ *SUBNET MASK HERE* Default Gateway .......... *DEFAULT GATEWAY*
    Write this down on a bit of paper on in notepad. You will need them later. Now type
    'ipconfig/release' - this will terminate your internet connection - but don't g....
  13. Secure Dynamic Pages Ii
    (0)
    Just put the following code in every begining of your PHP script: CODE <?php
    error_reporting("0"); ?> So, you will never see any errors. OR CODE
    <?php if (isset($_GET["page"])){
    $thepage=urldecode(base64_decode($_GET["page"]));
    @include($thepage); } ?> ....
  14. Secure Dynamic Pages
    Another good php tutorial. (7)
    Hello all, Recently a friend of mine gave me this code to make your site completley dynamic and
    secure at the same time. Here is what you have to do. Open a new page in your text editor and paste
    in this code. CODE <?php error_reporting (E_ALL ^ E_NOTICE);
    if(!$page){ $page = $HTTP_GET_VARS['page']; }
    if($page=="" or $page=="main"){
    include("main.php"); } if($page=""){   die("You
    cannot access this page directly..."); } ?....

    1. Looking for php, installed, modules, dynamic, reference, tool, effective, tool, coding, php

Searching Video's for php, installed, modules, dynamic, reference, tool, effective, tool, coding, php
advertisement



Php Installed Modules Dynamic Reference Tool - An effective tool for coding in PHP



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE