SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Handy functions

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Handy functions

    Hi

    I'm trying to have a list of must-learn functions, can someone recommend me some? Those like str_replace, you get the idea.

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure these are classed as 'must learn' but i find these functions useful and they are often overlooked in favour of slightly more common, but more verbose, solutions

    ctype
    ctype functions
    It's common to see people using regex for validation when often something like
    PHP Code:
    if(ctype_digit($var) === TRUE){ ... } 
    will do the job.

    Reading a file/remore web page into a var
    If you want to read a file, or a remote html page for example into a var..
    PHP Code:
    $var1 file_get_contents('somefile.txt');
    $var2 file_get_contents('http://foo.com/somepage.html');
    //if you don't have PHP >= 4.3.0 then you can instead use
    $var1 join(''file('somefile.txt'));
    $var2 join(''file('http://foo.com/somepage.html')); 
    Debugging
    error_reporting(E_ALL);
    print_r/var_dump
    mysql_error
    debug_backtrace

    Misc Stuff
    http://php.net/define - often overlooked in favor of $var =
    When doing DB operations quite often people will use 'complex' PHP code blocks/functions to do something which the DB can do natively. A prime example is manipulating dates from a db column. MySQL, for example, has some excellent built in functions for handling such stuff.

    Not a comprehensive list but i hope it helps some


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •