String Functions in PHP: Part 8

Introduction

In this article I describe the PHP string functions levenshtein, localeconv and ltrim. To learn some other math functions, go to:

  1. String Functions in PHP: Part1
     
  2. String Functions in PHP:Part2
     
  3. String Functions in PHP:Part3
     
  4. String Functions in PHP:Part4
     
  5. String Functions in PHP:Part5
     
  6. String Functions in PHP:Part6
     
  7. 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

localeconv()

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

ltrim(string, CharList)

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

Up Next
    Ebook Download
    View all
    Learn
    View all