Skip to content

Commit

Permalink
added text manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
lsv committed Sep 8, 2014
1 parent 76014a8 commit 2a11847
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Tests/TextManipulation15Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
class TextManipulation15Test extends PHPUnit_Framework_TestCase
{

public function dataProvider()
{
return [
[
'Java is a server-side scripting language. Java code can be simply mixed with HTML code. After the Java code is interpreted and executed, the web server sends resulting output to its client.',
'After The Php Code Is Interpreted And Executed, The Web Server Sends Resulting Output To Its Client.<br/>Php Code Can Be Simply Mixed With Html Code.<br/>Php Is A Server-side Scripting Language.'
],
[
'CakeJava is a popular Java framework.',
'Cakephp Is A Popular Php Framework.'
]
];
}

/**
* @dataProvider dataProvider
* @param string $input
* @param string $expected
*/
public function test_can_valid($input, $expected)
{
$this->assertEquals($expected, TextManipulation15::test($input));
}

}

31 changes: 31 additions & 0 deletions src/TextManipulation15.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: lsv
* Date: 9/4/14
* Time: 1:35 PM
*/

class TextManipulation15
{

static public function test($input)
{
$input = strtolower($input);
$input = preg_split('/\s+/', $input);
foreach($input as &$i) {
$i = ucfirst($i);
}
$input = join(' ', $input);

$input = str_replace('Java', 'Php', $input);
$input = str_replace('java', 'php', $input);
$input = str_replace('.', '<br/>', $input);

$input = preg_split('/<br\/>/', $input, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_OFFSET_CAPTURE);
$input = array_reverse(array_filter(array_map('trim', $input)));
$input = join('.<br/>', $input) . '.';
return $input;
}

}

0 comments on commit 2a11847

Please sign in to comment.