Programming
How to use chr() Function in PHP? PDF Print E-mail
Programming - PHP
Written by Khabza   
Tuesday, 31 January 2012 09:14

 

 

 

How to use chr() Function in PHP?

The chr() function returns a character from the specified ASCII value.

Syntax

chr(ascii)

The "ascii"parameter can be specified in decimal, octal, or hex values. Octal values are defined by a leading 0, while hex values are defined by a leading 0x.

Problem

<?php
echo chr(52)."<br />";
echo chr(052)."<br />";
echo chr(0x52)."<br />";
?>

Solution

4
*
R

Add a comment
 
How to use PHP chop() Function? PDF Print E-mail
Programming - PHP
Written by Khabza   
Sunday, 29 January 2012 21:35

 

 

How to use PHP chop() Function

 

The chop() function will remove a white space or other predefined character from the right end of a string. Specifies which characters to remove from the string.
The following characters are allowed and is set to be removed if the charlist parameter is empty:

  • "\0" - ASCII 0, NULL
  • "\t" - ASCII 9, a tab
  • "\n" - ASCII 10, a new line
  • "\x0B" - ASCII 11, a vertical tab.
  • "\r" - ASCII 13, a carriage return
  • " " - ASCII 32, an ordinary white space

Syntax

chop(string,charlist)

 

Problem

<?php
$str = "Hello World!\n\n";
echo $str;
echo chop($str);
?> 

Solution

Hello World!  Hello World!

Add a comment
 
How to use PHP bin2hex() Function? PDF Print E-mail
Programming - PHP
Written by Khabza   
Saturday, 28 January 2012 19:07

 

 

 

How to use PHP bin2hex() Function?

 

The bin2hex() function converts a string of ASCII characters to hexadecimal values. The string can be converted back using the pack() function.

 

Syntax

 bin2hex(string) 

 

Problem

<?php
 $str = "Hello world!";
 echo bin2hex($str) . "<br />";
 echo pack("H*",bin2hex($str)) . "<br />";
 ?>

Solution

48656c6c6f20776f726c6421
Hello world!

Add a comment
 
How to use PHP addslashes() Function PDF Print E-mail
Programming - PHP
Written by Khabza   
Saturday, 28 January 2012 18:01

 

 

 

How to use PHP addslashes () Function

The addslashes() function returns a string with backslashes in front of predefined characters. PHP runs addslashes() on all GET, POST, and COOKIE data by default. Therefore you should not use addslashes() on strings that have already been escaped, this will cause double escaping. The function get_magic_quotes_gpc() can be used to check this.

 

This function can be used to prepare a string for storage in a database and database queries.

 

The predefined characters  are:
- single quote (')
- double quote (")
- backslash (\)
- NULL

Syntax

addslashes(string)

Parameter

String is a required field

 

Problem

<?php
$str = "Who's Khabza?";
echo $str . " This is not safe in a database query.<br />";
echo addslashes($str) . " This is safe in a database query.";
?>

 

Solution

Who's Khabza? This is not safe in a database query.
Who\'s Khabza? This is safe in a database query.

 

 

 

Add a comment
 
How to user PHP addcslashes() Function PDF Print E-mail
Programming - PHP
Written by Khabza   
Thursday, 26 January 2012 10:17

The addcslashes() function returns a string with backslashes in front of the specified characters.

Syntax

addcslashes(string,characters)

Parameter
string is a required. Specifies the string to check
characters is a required. Specifies the characters or range of characters to be affected by addcslashes()

 

Note: Be careful using addcslashes() on 0, r, n and t. In PHP, \0, \r, \n and \t are predefined escape sequences.

 

Problem

We will add backslashes to certain characters in a string: add php openinh tag and closing tag to following code,

 

$str = "Hello, my name is Khabza.";
 echo $str."<br \>";
 echo addcslashes($str,'m')."<br \>";
 echo addcslashes($str,'K')."<br \>";

 

Solution

Hello, my name iskhabza.
Hello, \my na\me is Kabza.
Hello, my name is \Kabza.

Add a comment
 





GET OUR NEWSLETTER


Subscribe Newsletter
free poker

mod_cdlogin

Please install and enable Core Design Scriptegrator plugin.

Partner

Follow Me on Twitter

Add Me on Google+

Designed by Green IT Web © 2011