PHP levenshtein() Function
Complete PHP String Reference
Definition and Usage
The levenshtein() function returns the Levenshtein distance between two
strings.
The Levenshtein distance is the number of characters you have to replace,
insert or delete to transform string1 into string2.
By default, PHP gives each operation (replace, insert, and delete) equal
weight. However, you can define the cost of each operation by setting the
optional insert, replace, and delete parameters.
Syntax
|
levenshtein(string1,string2,insert,replace,delete)
|
| Parameter |
Description |
| string1 |
Required. First string to compare |
| string2 |
Required. Second string to compare |
| insert |
Optional. The cost of inserting a character.
Default is 1 |
| replace |
Optional. The cost of replacing a character.
Default is 1 |
| delete |
Optional. The cost of deleting a character.
Default is 1 |
Tips and Notes
Note: The levenshtein() function returns -1 if one of the strings
exceeds
255 characters.
Note: The levenshtein() function is not case-sensitive.
Note: The levenshtein() function is faster than the similar_text()
function. However, similar_text() will give you a more accurate
result with less modifications needed.
Example
<?php
echo levenshtein("Hello World","ello World");
echo "<br />";
echo levenshtein("Hello World","ello World",10,20,30);
?>
|
The output of the code above will be:
Complete PHP String Reference
Stylus Studio® 2010 XML Enterprise Suite raises the bar for productivity in XML development tools.
Millions of XML developers and data integration specialists turn to Stylus Studio's comprehensive and intuitive
XML toolset to tackle today's advanced XML data transformation and aggregation challenges.
|
- XML Pipeline Editor, Debugger and Code Generator
- DataDirect XML Converters
- XQuery Mapper, Editor, Debugger, and Profiler
- XSLT Mapper, Editor, Debugger, Designer, and Profiler
- Java and C# for .Net Code Generation
- XML Schema Designer With Documentation Generator
- XML Editor With Full XPath Integration
Download a free trial now
|
|