Introduction
In this article I describe the PHP string functions levenshtein, localeconv and ltrim. To learn some other math functions, go to:
- String Functions in PHP: Part1
- String Functions in PHP:Part2
- String Functions in PHP:Part3
- String Functions in PHP:Part4
- String Functions in PHP:Part5
- String Functions in PHP:Part6
- String Functions in PHP:Part7
PHP levenshtein() Function
The PHP string levenshtein function calculates the levenshtein string between two strings.
Syntax
levenshtein(string1, string1, insert, replace, delete) |
Parameter in levenshtein function
The parameters of the levenshtein function are:
Parameter |
Description |
string1 |
It specifies the first string to compare. |
string2 |
It specifies the second string to compare. |
insert |
It defines the cost of insertion. |
replace |
It defines the cost of replacement. |
delete |
It specifies the cost of deletion. |
Example
An example of the levenshtein function is:
<?php
echo levenshtein("MCN Solution","CN Soluti")."</br>";
echo levenshtein("MCN Solution","CN Soluti",5,10,15);
?>
Output
![levenshtein-string-function-in-php.jpg]()
PHP localeconv() Function
The PHP string localeconv function gets the numeric formatting information and returns an associative array containing localized numeric and monetary formatting information.
Syntax
Example
An example of the localeconv function is:
<?php
$information = localeconv();
echo "<pre>";
print_r($information);
?>
Output
![localeconv-string-function-in-php.jpg]()
PHP ltrim() Function
The PHP string ltrim function will remove whitespaces or other predefined characters from the left side of a string.
Syntax
Parameter in ltrim Function
The parameters of the ltrim function are:
Parameter |
Description |
string |
It specifies the string to check. |
CharList |
It specifies the characters to be removes from the string. |
Example
An example of the ltrim function is:
<?php
$str=' MCN Solution';
echo "Without using ltrim:" .$str."</br>";
echo "With--- using ltrim:" .ltrim($str)."</br>";
?>
Output
![ltrim-string-function-in-php.jpg]()
Source Code of browser window
You can see in the following image of source code that the first time we we simply show the string without the ltrim function, the original string is shown, but when we use "ltrim($str)", the white space has been removed.
![ltrim-string-function1-in-php.jpg]()