Skip to content

Instantly share code, notes, and snippets.

@crynobone
Created March 10, 2011 21:20
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 crynobone/864952 to your computer and use it in GitHub Desktop.
Save crynobone/864952 to your computer and use it in GitHub Desktop.
<?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