5 Less Known PHP Functions

As all of you know that PHP has a large set of functions for the programmers. The list is so huge that we keep on learning each one of them day by day. There are some cases you would like to know them beforehand to use them in your app. These are those functions which may be famous for some, but largely people are ignorant about their existance. Here goes the list.

  1. highlight_string: When you want to give away some PHP code as example and want it syntax highlighted, what would be your next step? Get some highlighting plugin? Use this function, pass the string and the highlighted string is printed as the output. If you don’t want to print it, instead want to store in some variable, pass the second variable as true. Details
  2. htmlspecialchars: If you have a HTML code to show as an example and want to print it out on the page, simply echoing wont suffice, since the tags would be rendered by the browser as HTML tags. This function converts < to &lt; and > to &gt; and other such special chars into their respective representation. Details
  3. chr: It is used to convert a number to its ASCII character. The paramter of the function is the integer and output is the character from the ASCII table. Details
  4. ord: This is just the reverse of chr. It takes a single character as input and returns back the ASCII value of the character. It’s a reverse mapping of chr. Details
  5. xdiff_file_diff : Taking file differences is one of the oldest thing which existed on a computer. The *nix diffutils is a great source of diff for system admins. Let’s make it available on PHP too. this function takes 3 compulsory arguments – first is the old file, second is the new file and the third being the difference file where the diff is stored. You can use the xdiff_file_patch to patch the files. Details
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s