Basic Tutorial : PHP String Function (Explode, Implode, STR Replace, Parse STR, MD5) And Example

Share:

Basic Tutorial : PHP String Function (Explode, Implode, STR Replace, Parse STR, MD5) And Example. PHP string function is used to manipulate a string to a wide range of programming needs in php. One example is the md5 string, used to protect the login password on a website. If you are a web development, you should be able to master the basic php mainly php string function. Therefore, in this tutorial post, we will discuss some php string function that is often used in making web application program. Learn more …
Basic Tutorial : PHP String Function (Explode, Implode, STR Replace, Parse STR, MD5) And Example

Basic Tutorial : PHP String Function (Explode, Implode, STR Replace, Parse STR, MD5) And Example

PHP Explode String Function
PHP explode () function is used to split a string by a certain separator and insert the results into an array variable.
Syntax :

explode(string $delimiter , string $string [, int $limit ])

Parameters :
$delimiter : string delimiters.
$string : string to be shared.
$limit : The maximum limit of the array elements are created.
Example Of PHP Explode() String Function :

<?php
$str = 'one|two|three|four';
print_r(explode('|',$str));
// just 2 array element
print_r(explode('|', $str, 2));
?>

PHP Implode String Function
The usefulness of this function is the inverse function rather than explode. Implode function is used to generate a string from each element of an array. The resulting string is separated by a string has been predetermined.
Syntax :

implode([string $among] , array $array)

parameters:
$among, string or character between the elements to be incorporated, is optional, can be filled or not.
$array, array to be changed.
Example Of PHP Implode() String Function :

<?php
$array = array('name', 'email', 'website');
$result = implode("&",$array);
echo $result;
?>

PHP STR_Replace String Function
PHP str_replace function to replace the searched string with another string.
Syntax :

str_replace( mixed $search, mixed $replace, mixed $subject [, int &$count ])

parameters:
$search, is part of the string is to be replaced.
$replace, is the replacement string.
$subject, is the string to be processed.
$count, the number of matching parts and replaced.
Example Of PHP STR_Replace String Function :

<?php
$str = "I learning PHP string function";
$str2 = str_replace("ing"," ",$str,$count);
echo $str2."<br>";
echo $count;
?>

PHP Parse_STR String Function
PHP Parse_str function to convert a string into a variable. In web development, this function has great benefits. We can get a query string of the dynamic url and retrieve the value of a variable by using the PHP parse_str function.
Syntax :

parse_str( string $str, array $arr )

Parameters:
$str, is a string that will be converted.
$arr, is output in the form of an array.
Example Of PHP Parse_STR() String Function :

<?php
$str = "name=Denny&email=denny@world.edu";
parse_str($str);
echo $nama;                 // Result Denny
echo $email;                // Result denny@world.edu

parse_str($str, $output);
echo $output['nama'];       // Result Denny
echo $output['email']       // Result denny@world.edu
?>

PHP MD5 String Function
As in theopening description, php md5 function useful to encrypt the string that is one-way, meaning there is no function to restore it unless you wear a special hacking code so it is safe to protect a website from a hacker.
Syntax :

md5($string)

Example Of PHP MD5 String Function :

<?php
$password = "bs6$TY9^z0"lo)";
echo md5($password);
?>

Actually there are many other php string functions but in this tutorial we discussed the five string, may be we will continue to the next tutorial.
Thanks for reading Basic Tutorial : PHP String Function (Explode, Implode, STR Replace, Parse STR, MD5) And Example

[Tutorial.World.Edu]

Leave a Reply

Your email address will not be published. Required fields are marked *