Beispiel #1
0
 public function testStr()
 {
     $original = 'Hello world!';
     $chars = 'o,e';
     // you can list all chars
     $charsForPattern = str_ireplace(',', '', $chars);
     $result = processStr($original);
     $this->assertInternalType('string', $result);
     $this->assertNotRegExp('/[' . $charsForPattern . ']/i', $result);
     $this->assertNotEquals($result, $original);
     if (strlen($result) == strlen($original)) {
         $this->assertEquals($result[0], substr($original, -1));
     } else {
         $this->assertLessThan(strlen($original), strlen($result));
     }
 }
Beispiel #2
0
<?php

/**
 * Created by PhpStorm.
 * User: al
 * Date: 17.11.15
 * Time: 14:36
 */
$str = 'Hello world!';
function processStr($str)
{
    $str = strrev($str);
    $chars = explode(',', 'o,e');
    // all chars
    $str = str_ireplace($chars, '', $str);
    return $str;
}
echo processStr($str);