.

Tuesday, October 25, 2011

PHP code - fclose

fclose() function is used to close an open file:



Syntax:
fclose()
Example:
<?php
$file = fopen("phpcode.txt","r");

//some code to be executed

fclose($file);
?>

Monday, October 24, 2011

PHP code - stripslashes

stripslashes() function is  removes backslashes.



Syntax:
stripslashes(string)

string = Specifies the string to check
Example:
<?php
$string="Easy way\'s to learning php";
$stripslashes=stripslashes($string);

echo $stripslashes;
?>

Result:
Easy way's to learning php

Sunday, October 23, 2011

PHP code - fopen

fopen() function is used to open files in PHP.



Syntax :
fopen(url,mode)

url = url file to open
mode = file open by following modes :


r Read only. Starts at the beginning of the file
r+ Read/Write. Starts at the beginning of the file
w Write only. Opens and clears the contents of file; or creates a new file if it doesn't exist
w+ Read/Write. Opens and clears the contents of file; or creates a new file if it doesn't exist
a Append. Opens and writes to the end of the file or creates a new file if it doesn't exist
a+ Read/Append. Preserves file content by writing to the end of the file
x Write only. Creates a new file. Returns FALSE and an error if file already exists
x+ Read/Write. Creates a new file. Returns FALSE and an error if file already exists

Example:
<html>
<body>

<?php
$file=fopen("phpcode.txt","r");
?>

</body>
</html>

Thursday, October 20, 2011

PHP code - floor

floor() function is returns the value of a number rounded downwards to the nearest integer.



Syntax :
floor(x)

x = number
Example :
<?php
$number="4.5";
$floor=floor($number);

echo $floor;
?>

Output :
4

Wednesday, October 19, 2011

PHP code - strip_tags

strip_tags() function is strips a string from HTML, XML, and PHP tags.



Syntax :
strip_tags(string)

string = Specifies the string to check

Example :
<?php
$string="<p>PHP CODE</p>
<p>Easy way to learning PHP</p>
";
$strip_tags=strip_tags($string);

echo $strip_tags;
?>

Output :
Easy way to learning PHP

Tuesday, October 18, 2011

PHP code - sort

sort() function is sorts an array by the values.



Syntax :
sort(array)

array = Specifies the array to sort

Example:
<?php
$array = array("easy","way","to","learning", "php", "code");

sort($array);
print_r($array);
?>

Output:
Array ( [0] => code [1] => easy [2] => learning [3] => php [4] => to [5] => way )

PHP code - shuffle

shuffle() function is  randomizes elements in the array.



Syntax :
shuffle(array)

array= Specifies the array to use

Example:
<?php
$array = array("easy","way","to","learning", "php", "code");

shuffle($array);
print_r($array);
?>

Output:
Array ( [0] => code [1] => php [2] => easy [3] => learning [4] => to [5] => way )

PHP code - round

The round() function is a number to the nearest integer.



Syntax:
round(x)

x = number

Example:
<?php
$number=0.6;

$round=round($number);

echo $round;

?>

Output :
1

PHP code - ceil

The ceil() function is to returns the value of a number rounded UPWARDS to the nearest integer.


Syntax:
ceil{x}

x= number

Example:

<?php
$number_1=9;
$number_2=5;
$ceil=ceil($number_1/$number_2);

echo $ceil;
?>

Output :
2

Monday, October 17, 2011

PHP code - ucwords

The ucwords() function is to converts first character of each word in a string to uppercase.



Syntax :
ucwords(string)

Example :
<?php
$string="easy way to learning php";
$ucwords=ucwords($string);

echo $ucwords;

?>

Output :
Easy Way To Learning Php

PHP code - strtoupper

strtoupper() function is to convert a string to uppercase



Syntax :
strtoupper(string)
Example:
<?php
$string="easy way to learning php";
$uppercase=strtoupper($string);

echo $uppercase;

?>

Output:
EASY WAY TO LEARNING PHP

PHP code - str_replace

function str_replace() is to replace some character with other character.



Syntax :
str_replace(find,replace,string)

find = the value to find.
replace = the value to replace
string =  the string to be searched
Example :
<?php
$string="easy way to learning php";
$find="php";
$replace="php codex";
$output= str_replace($find,$replace,$string);

echo $output;

?>

Output :
easy way to learning php code