- str_replace: documentation ( source)
- strtolower: documentation ( source)
<?php
namespace SComparison;
class Comparator
{
protected $_strings = array();
protected $_tests = array();
protected $_hash;
public function __construct()
{
$this->_hash = new SHash();
}
/**
* converting input data
*/
protected function _prepareInput()
{
foreach ($this->_strings as $key => $string) {
$this->_tests[$key] = str_replace(" ", "", strtolower($string));
}
}
protected function _outputInteractive($key)
{
echo "String: " . $this->_strings[$key] . "\n";
echo "Test: " . $this->_tests[$key] . "\n";
echo "Hash: " .
$this->_hash->getHash(SHash::HASH_BIN) .
" - " .
$this->_hash->getHash() .
"\n";
echo "-----------------------------------------------------------\n";
}
/**
* executing comparison action
*/
public function runInteractive()
{
$this->_prepareInput();
foreach ($this->_tests as $key => $test) {
$this->_hash->setString($test);
$this->_hash->getHash();
$this->_outputInteractive($key);
}
}
public function runCL()
{
$this->_prepareInput();
foreach ($this->_tests as $key => $test) {
$this->_hash->setString($test);
$this->_hash->getHash();
$this->_outputInteractive($key);
}
}
public function setStrings(array $strings)
{
$this->_strings = $strings;
}
}