3v4l.org

run code in 200+ PHP versions simultaneously
<?php // SELECT `link_id`, `link_name`, `alias` FROM `m5cob_mt_links` WHERE `alias` = '' // indexed resultset... $resultset = [ [6, 'Convivio Bar & Restaurant Chester Cheshire UK', ''], [7, 'Slug and Lettuce Chester Cheshire UK', ''], [8, 'Da Rosa Restaurant 1 & Wine Bar Torrevieja Costa Blanca Spain', ''], [9, 'Bar Lounge Chester Cheshire UK', ''], [10, 'Telfords Warehouse Chester Cheshire UK', ''], [11, 'The Botanist Chester Cheshire UK', ''], [12, 'Missoula Chester Cheshire UK', ''], [13, 'Fiesta Havana Chester Cheshire UK', ''], [14, 'El Oceano\'s Hotel Restaurant, Torrenueva, Marbella, Malaga', ''], [15, 'La Plaza Restaurant Riviera del Sol Mijas Costa Malaga Spain', ''] ]; foreach ($resultset as $row) { $purged = preg_replace('~[^a-z ]+~', '', strtolower($row[1])); $split = preg_split('~ +~', $purged, 6, PREG_SPLIT_NO_EMPTY); $new_alias = implode('-', array_slice($split, 0, 5)); echo "{$row[0]}: $new_alias\t\t(from: {$row[1]}\n"; // UPDATE `m5cob_mt_links` SET `alias` = '$new_alias' WHERE `link_id` = $row[0] }