Skip to content

Instantly share code, notes, and snippets.

@carbontwelve
Last active December 23, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carbontwelve/6639350 to your computer and use it in GitHub Desktop.
Save carbontwelve/6639350 to your computer and use it in GitHub Desktop.
<?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