Cool Functions Most People Don't Know About PHP

Postat pe - Modificat ultima dată pe

PHP is one of the most popular open-source scripting languages used for Web development, and it can be imbedded within HTML.  The focus with PHP is server-side scripting, and there are several powerful functions that can be used to do delicate and handy operations quickly and accurately.


·         List()


The list function is one that most PHP developers learn early on and have a tendency to forget as their skills progress. This function can unpack numeric arrays that can also be used to change the value of two variables.  List() is PHP's way of assigning values to multiple variables, and in many cases, works better than $result.


·         Extract()


Extract() is yet another function many developers learn early on but tend to forget later.  Extract() is a function that can be used to move scope variables from one place to another.  Scope variables can be packed in an array with get_defined_vars(), or by using compact().  They can then be unpacked in another place using the extract() function. 


Extract() may also be used for template engines.  Simple template engines allow variables to be set in one place via the use of associative arrays and then be accessed as normal variables. 


·         _autoload()


_autoload() is another handy function PHP developers need to be aware of.  This function is called from behind the scenes when a class that is non-existent is instantiated.  Autoload will work by taking in a class name, and then attempt to find the file the class is in.  It will then include it and allow the program to continue running. 


You must be very careful in using this function though, and it is suggested that it not be directly implemented.  Since autoload has no name space, it will generate errors if two or more apps are running simultaneously and they happen to share common files that both define the autoload function.


·         highlight_string()


This function can be helpful when one wants to display PHP code on a website.  It will return a syntax-highlighted version of PHP code, and it will use the colors that are predefined in the syntax highlighter for the scripting language. 


·         str_word_count()


This is a function in PHP that takes a string that you as a developer give it as a parameter, and returns the number of words it contains.  


·         Levenshtein()


If you ever have a need to compare how different or how similar two words are, the levenshtein() function is what you need and it is very useful for tracking user typos. 


·         get_defined_vars()


This is a function that will come in very handy during the testing phase of an app.  Get_defined_vars() returns a multi-dimensional array that has a list of all of the defined variables, and they can be environmental, user-defined, or server variables that are within the scope of where this function is called.


All of these functions will come in handy at one time or another if you are a PHP developer.

Postat: 22 aprilie, 2015


Proofreader, Editor, Writer and App Developer

Do you need a professional editor and writer to proofread your technical documents, thesis, novel, statement of purpose, personal statement, resume, cover letter, manuscript, essay, short story, textbook content, or articles? Do you want to make sure that your marketing material content is flawless and appealing to readers? I can do any of that! I am a professional editor (academic, copy, line/su...

Următorul articol

Effective Product Sourcing Research Resources