soundex
-
This function’s solution requires the text gem.
We can calculate the
soundexkey 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
PHP
$result = soundex("hello world"); var_export($result); // => 'H464'
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::Soundex.soundex(text) # => "H464"
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.

