Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$string_create = 'create_some_long_tablename';
$string_add = 'add_some_tablename_to_other_long_table_name';
function get($string) {
$string = str_replace(array('create_', 'add_','_to_'), array('create-', 'add-', '-to-'), $string);
if (preg_match('/^(create|add)\-([A-Za-z0-9\_]*)(\-to\-)?([A-Za-z0-9\_]*)?$/i', $string, $matches)) {
if ($matches[1] == 'create') {
echo $matches[2];
}
else if ($matches[1] == 'add') {
echo $matches[2] . ' to ' . $matches[4];
}
}
else {
echo 'failed';
}
print '<br />';
}
get($string_create);
get($string_add);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment