<?php $re = '/\bsite_[a-zA-Z0-9]*/'; $query = 'SELECT * FROM site_customers LEFT JOIN site_products'; preg_match_all($re, $query, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches); // Replace old tables with new ones $old = [ $matches[0][0], // First table name $matches[1][0], // Second table name ]; $new = [ $matches[0][0] . '_02', // Append _02 'new_' . $matches[1][0], // Prepand new_ ]; $query = str_replace($old, $new, $query); // Print the new query echo $query;
You have javascript disabled. You will not be able to edit any code.