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])); // lowercase, then remove unwanted chars $split = preg_split('~ +~', $purged, 6, PREG_SPLIT_NO_EMPTY); // explode on 1 or more spaces, max of 6 elements, no empty elements $new_alias = implode('-', array_slice($split, 0, 5)); // remove 6th element if it exists, re-glue with hyphens echo "{$row[0]}: $new_alias\t\t(from: {$row[1]}\n"; // UPDATE `m5cob_mt_links` SET `alias` = '$new_alias' WHERE `link_id` = $row[0] }
based on gijfh
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 40
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 40
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/8NtZd
function name:  (null)
number of ops:  42
compiled vars:  !0 = $resultset, !1 = $row, !2 = $purged, !3 = $split, !4 = $new_alias
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   5     0  E >   QM_ASSIGN                                                !0
  17     1      > FE_RESET_R                                       $6      !0, ->40
         2    > > FE_FETCH_R                                               $6, !1, ->40
  18     3    >   INIT_FCALL                                               'preg_replace'
         4        SEND_VAL                                                 '%7E%5B%5Ea-z+%5D%2B%7E'
         5        SEND_VAL                                                 ''
         6        INIT_FCALL                                               'strtolower'
         7        FETCH_DIM_R                                      ~7      !1, 1
         8        SEND_VAL                                                 ~7
         9        DO_ICALL                                         $8      
        10        SEND_VAR                                                 $8
        11        DO_ICALL                                         $9      
        12        QM_ASSIGN                                                !2
  19    13        INIT_FCALL                                               'preg_split'
        14        SEND_VAL                                                 '%7E+%2B%7E'
        15        SEND_VAR                                                 !2
        16        SEND_VAL                                                 6
        17        SEND_VAL                                                 1
        18        DO_ICALL                                         $11     
        19        QM_ASSIGN                                                !3
  20    20        INIT_FCALL                                               'implode'
        21        SEND_VAL                                                 '-'
        22        INIT_FCALL                                               'array_slice'
        23        SEND_VAR                                                 !3
        24        SEND_VAL                                                 0
        25        SEND_VAL                                                 5
        26        DO_ICALL                                         $13     
        27        SEND_VAR                                                 $13
        28        DO_ICALL                                         $14     
        29        QM_ASSIGN                                                !4
  21    30        FETCH_DIM_R                                      ~16     !1, 0
        31        ROPE_INIT                                     6  ~19     ~16
        32        ROPE_ADD                                      1  ~19     ~19, '%3A+'
        33        ROPE_ADD                                      2  ~19     ~19, !4
        34        ROPE_ADD                                      3  ~19     ~19, '%09%09%28from%3A+'
        35        FETCH_DIM_R                                      ~17     !1, 1
        36        ROPE_ADD                                      4  ~19     ~19, ~17
        37        ROPE_END                                      5  ~18     ~19, '%0A'
        38        ASSIGN_OBJ                                               ~18
  17    39      > JMP                                                      ->2
        40    >   FE_FREE                                                  $6
  24    41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 7.4.0