My PHP voyage …

20-May-2008, I decided to write some thing abt either PHP, GRE and something generally on programming regularly here.There was a temporary power-cut for about 45min (throughout Neyveli, which rarely happens) which forced me to take the PHP book I had stacked in my room (again Truth be revealed : I had borrowed two books from my college library to pass the vacation which trivially is stacked up amongst other books undisturbed).

The book doesn’t offer an introduction to PHP (which I already have a bit) rather it discusses some problem specific coding in various aspects of PHP.

Oh forgot to tell PHP – PHP Hypertext Preprocessor – a reverse acronym like GNU which is GNU is Not UNIX.

Some interesting functions that I came across today:

1. Backtick ` ` – As in the case of shell scripts the back-tick is used to tell the compiler/interpretor to interpret characters within “ as shell commands.

eg: `dir`

2. htmlspecialchars() – It is used to prevent the browser from interpreting special text within < >

eg: It is used to avoid interpretation of <DIR> in the generated output of ‘dir’ command.

3. chcp – Used to change the encoding.

eg: cp866 is DOS encoding and cp1251 is Windows encoding.The output of `dir` command will be in cp866 and can be directly printed to screen using echo `dir`.So the encoding must be explicitly changed by giving `chcp 1251`.Doing echo `chcp` will give you the current encoding

4. convert_cyr_string() – Instead of chcp-ing to change the encoding this function can also be used to change the encoding.

Syntax: convert_cyr_string(string $string,string $from,string $to)

where $from,$to is one of :

  • k – koi8-r
  • w – windows-1251
  • i – iso8859-5
  • a/d – x-cp866
  • m – x-mac-cyrillic

eg: convert_cyr_string(htmlspecialchars(`dir`),’d’,’w’)

5. str_repeat() – Used to repeat the given set any no. of times.

eg: str_repeat(” “,10)

6. implode() – to join array elements into a single string with some string inbetween each element

like element1seperator_stringelement2seperator_stringelement3…..

eg: implode(“&filename[]=”,$filename)

where $filename is an array

7. serialize() and unserialize() – used to store a byte stream version of the whatever is specified into a single string.Similar to above but here the structure of each and every element is preserved and re-converted using unserialize().

eg: $content=serialize($filename);

$filename=unserialize($content);

where $filename is a array and $content is a single string

8. stripcslashes(),stripslashes(),stripslashes_deep() – stripslashes() is used to strip slashes as its name infers.

O\’reilly -> O’reilly

stripslashes_deep() is used to do this recursively.

stripslashes_deep($arrayname)

stripcslashes() is similar to stripslashes() except that it recognize C-like escape sequences \n,\r,\x,…

That’s all for today.Hope to continue this regularly.

Advertisements

~ by toolweb on May 20, 2008.

One Response to “My PHP voyage …”

  1. hey write more.
    and soon. bcoz i need it!! 😛

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

 
%d bloggers like this: