Skip to content

Instantly share code, notes, and snippets.

@flangofas
Created August 3, 2016 14:30
Show Gist options
  • Save flangofas/14444230eec53b5246483e659806116e to your computer and use it in GitHub Desktop.
Save flangofas/14444230eec53b5246483e659806116e to your computer and use it in GitHub Desktop.
Creating alias out of given name
<?php
$items = [
'Aluminium Manufacturing',
'Cement Manufacturing',
'Chemicals',
'Chemicals - Fertilizers',
'Chemicals - Methanol',
'Construction',
'Contract Laboratory Services',
'Education',
'Electronics',
'Energy',
'Engineering',
'Food & Beverage',
'Gas Processing',
'Gas Upstream',
'Goverment',
'Manufacturing',
'Mining & Minerals',
'Other',
'Petrochemicals',
'Petroleum - Terminals',
'Petroleum - Lubricants',
'Petroleum - Refining',
'Pharma',
'Sales Agent',
'Steel Manufacturing',
'Utilities',
'Power Generation',
];
echo PHP_EOL;
foreach ($items as $i) {
$alias = str_replace(' ', '_', $i);
$alias = preg_replace('/[^A-Za-z0-9\_]/', '', $alias);
$alias = str_replace('__', '_', $alias);
$alias = strtolower($alias);
$display = $i;
echo "$alias, $display," . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment