Last active
December 23, 2015 12:59
-
-
Save carbontwelve/6639350 to your computer and use it in GitHub Desktop.
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
<?php | |
function explodeArrayFunction($input) | |
{ | |
$array = preg_split('/(\s|[\.,\/])/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); | |
return array_values($array); | |
} | |
function implodeArrayFunction($input) | |
{ | |
$text = implode('', $input); | |
return $text; | |
} | |
$input = "This is some sample input, it's not complex. "; | |
$input .= "But does contain punctuation such as full stops/back-slashes/etc"; | |
$array = explodeArrayFunction($input); | |
$testArray = array( | |
"This", | |
" ", | |
"is", | |
" ", | |
"some", | |
" ", | |
"sample", | |
" ", | |
"input", | |
",", | |
" ", | |
"it's", | |
" ", | |
"not", | |
" ", | |
"complex", | |
".", | |
" ", | |
"But", | |
" ", | |
"does", | |
" ", | |
"contain", | |
" ", | |
"punctuation", | |
" ", | |
"such", | |
" ", | |
"as", | |
" ", | |
"full", | |
" ", | |
"stops", | |
"/", | |
"back-slashes", | |
"/", | |
"etc", | |
); | |
var_dump($input); | |
var_dump($testArray); | |
var_dump($array); | |
if ($array == $testArray) { | |
echo 'PASS ARRAY COMPARISON </br>'; | |
} else { | |
echo 'FAIL ARRAY COMPARISON </br>'; | |
} | |
$test = implodeArrayFunction( $array ); | |
var_dump($test); | |
if ($test == $input) { | |
echo 'PASS STR COMPARISON </br>'; | |
} else { | |
echo 'FAIL STR COMPARISON </br>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment