New PHP programmer looking for advice on my 1st 2 functions.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grill8
Forum Newbie
Posts: 2
Joined: Fri Sep 05, 2008 12:39 am

New PHP programmer looking for advice on my 1st 2 functions.

Post by grill8 »

Hello all,
My name is Jeremy and I am an experienced programmer but not to PHP. These are my first two PHP functions and I would love some advice as to whether there are optimizations, language functionalities etc. that could improve the following two functions. They need to be PHP 4 compatible.
The first function simply extracts an array of tokens (separated by whitespace and a preceding character ~ before each token) from a file and skips over comments at the top of the file.
The second function extracts (from the array from function 1) arrays of objects who have a given number of tokens per object. The first token in the array passed to this function is the number of objects and all subsequent tokens are groupings of data objects whos number is passed as an argument.

Any help/optimizations etc. would be greatly appreciated. Thank you for your help.

Without further adieu ... here are the functions:

Code: Select all

 
function 
_ExtractScriptTokens
(
     $Scpt,
     &$rTkns
)   
{
     $Hndl = fopen($Scpt, "r");
     if(FALSE === $Scpt)
     {
          return ( FALSE );
     }
     do
     {
          $Char = fgetc($Hndl);
     }
     while("~" !== $Char);
     $Strm = fread($Hndl, filesize($Scpt) - ftell($Hndl));
     fclose($Hndl);
     $rTkns = explode("~", $Strm); 
     return ( (FALSE === $rTkns)?FALSE:TRUE );
}
 
 
function
_ExtractFSResourceArray
(
     $NObjTkns,
     &$rTkns,
     &$rResAry  
)
{
     $NObjs = current($rTkns);
     if(FALSE === $NObjs) 
     {
          return ( FALSE );
     }
     for($iObj = 0; $iObj < $NObjs; ++$iObj)
     {
          for($iElmnt = 0; $iElmnt < $NObjTkns; ++$iElmnt)
        {   
               $Tkn = next($rTkns);
               if(FALSE === $Tkn)
               {
                return ( FALSE );
           }    
               $rResAry[$iObj][$iElmnt] = $Tkn;
          }
     }
     return ( (FALSE === next($rTkns))?FALSE:TRUE );
}
 
Last edited by onion2k on Fri Sep 05, 2008 2:46 am, edited 7 times in total.
Reason: Fixed code tags
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: New PHP programmer looking for advice on my 1st 2 functions.

Post by andyhoneycutt »

I don't mean to seem too lazy here, but could you edit your post and enclose them in php tags, or code=php tags? This late at night it's difficult to follow without a little indentation.

-Andy
User avatar
pcoder
Forum Contributor
Posts: 230
Joined: Fri Nov 03, 2006 5:19 am

Re: New PHP programmer looking for advice on my 1st 2 functions.

Post by pcoder »

Edit like

Code: Select all

not like [code="php"].
Post Reply