function wrap_outer_tables($html) {
$regex = '/<table([^>]*)>([\s\S]*?)<\/table>/i';
$matches = array();
preg_match_all($regex, $html, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$inner_tables = '';
preg_match_all($regex, $match[2], $inner_tables, PREG_SET_ORDER);
if (empty($inner_tables)) {
$replacement = '<div class="q">' . $match[0] . '</div>';
$html = str_replace($match[0], $replacement, $html);
} else {
$inner_html = wrap_outer_tables($match[2]);
$replacement = '<table' . $match[1] . '>' . $inner_html . '</table>';
$html = str_replace($match[0], $replacement, $html);
}
}
return $html;
}
$html = '<table class="любой или без класса"><tbody>
<table class="sdf"><tbody>
</tbody></table>
<table><tbody>
</tbody></table>
</tbody></table>';
$html = wrap_outer_tables($html);
echo $html;
<div class="q"><table class="любой или без класса"><tbody>
<table class="sdf"><tbody>
</tbody></table>
<table><tbody>
</tbody></table>
</tbody></table></div>
return [
'dsn' => 'mysql:host=localhost;dbname=test;charset=utf8',
'user' => 'root',
'password' => '',
];
<?php
namespace wfm;
require_once 'vendor/autoload.php';
use RedBeanPHP\R;
class Db
{
use TSingleton;
private function __construct()
{
if (!defined('CONFIG')) {
define('CONFIG', __DIR__ . '/config');
}
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$db = require CONFIG . '/config_db.php';
R::setup($db['dsn'], $db['user'], $db['password']);
if (!R::testConnection()) {
throw new \Exception('No connection to DB', 503);
}
R::freeze(true);
if (DEBUG) {
R::debug(true, 3);
}
}
}
if ( isset ( $_POST['id'] ) )
{
$ids = implode( ',', $_POST['id'] );
$query = ("
INSERT INTO
`order_archive` (`id`, `user_id`, `articul_id`, `barcode`, `quantity`)
SELECT
`id`, `user_id`, `articul_id`, barcode`, `quantity`
FROM
`order`
WHERE
`id` IN ($ids);
DELETE FROM `order` WHERE `id` IN ($ids)");
if(mysqli_multi_query($db, $query)) {
echo 'Customer removed: ' .$ids;
} else {
echo "Error querying database: " . mysqli_error($db);
}
}