-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |