metaphone
-
This function’s solution requires the text gem.
We can calculate the
metaphonekey of a string in Ruby with the help of the text gem. To install this gem:$> sudo gem install Text Successfully installed Text-1.1.2 1 gem installed
Once this gem is installed, we can calculate the
metaphoneusingPHP
$result = metaphone("hello world"); var_export($result); // => 'HLWRLT'
To get the equivalent of the string in PHP, we need to first strip whitespace from the string.
Ruby
require 'rubygems' require 'text' text = "hello world".gsub(/\s/, '') p Text::Metaphone.metaphone(text) # => "HLWRLT"
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

