Some Imp PHP Functions

Some Imp PHP Functions: Hi Readers, Today in this tutorial we have explained some of the PHP Functions which is generally used in your Project or Program in Between.

explode():

This PHP Function is used to Split a Character Array i.e String at a particular Position or Symbol. This Symbol is referred as a Delimiter.

In other words, we can say that If we want to break a String into Smaller pieces at a particular point we can use a explode() functions in PHP.

Here is Simple Example which clears the concept of explode() functions.

<!DOCTYPE html>
<html>
<body>
<h3>Use of Explode() Function, Here Delimiter: " " (Space)</h3>
<?php
$string="explode() function break the String into smaller pieces!";
$result=explode(" ",$string);
print_r($result);
?>
</body>
</html>

ScreenShot:

Some Imp PHP functions


implode():

This PHP Function is used to combines all elements of an array into a String using a Delimiter. A Delimiter can be any symbol (%,/,*,etc…),

any character, word, String, and even it can be an empty String (” “) i.e., Space in between two words.

In other words, we can say that If we want to Join pieces of String or no of characters into a long String we can use an implode() functions in PHP.

Here is Simple Example which clears the concept of implode() functions.

Use of Implode() Function, Here Delimiter: ” ” or / (Slash) or (..)

<!DOCTYPE html>
<html>
<body>
<h3>Use of Implode() Function, Here Delimiter: " "Space or /(Slash) or ..(point)</h3>
<?php
$array=array('implode()','function','is','used','to','join','a','character','array','into','string','using','Delimiter');
$result=implode(" ",$array);
$result1=implode("/",$array);
$result2=implode("..",$array);
echo "$result<br /><br />$result1<br /><br />$result2";
?>
</body>
</html>

ScreenShot:

Some Imp PHP Functions


ctype_alnum():

This function is generally used when we want to check for the given String contains Alphanumeric Character(s) or not

Syntax:

bool ctype_alnum ( string $txt )

here, $txt: any given String which we want to check for Alphanumeric Characters

As ctype_alnum() is a boolean function so it will return either TRUE or FALSE.

Here is Simple Example which clears the concept of ctype_alnum() functions.

<?php
$string= array('A1234bCsghjks', 'wrong!%WA#$gh');
echo "string[0]=>$string[0],<br />string[1]=>$string[1]<br />";

foreach ($string as $case) {
 if (ctype_alnum($case)) {
 echo "<br />String <b>$case </b>consists of only alphanumeric Characters i.e., letters or digits.<br />";
 } else {
 echo "<br />string <b>$case</b> does not consist Alphanumeric Characters i.e.,only letters or digits.\n";
 }
}
?>

ScreenShot:

Some Imp PHP Functions


Some Similar functions as ctype_alnum() are as follows:

ctype_alpha():

This boolean function returns TRUE if all the characters in given string are Alphabets only i.e., it does not contain digits or any Symbols or Special Characters.

ctype_digit():

 This boolean function returns TRUE if all the characters in given string are Digits only i.e., it does not contain Alphabets or any Symbols or Special Characters.


I Hope You would like this tutorial on Some Imp PHP Functions!

Leave a Comment