Ici un cas concret sous Prestashop.
Ce code permet de changer tous les http en https sur tous les contenus :
<?php require(dirname(__FILE__) . '/config/config.inc.php'); $aData = Db::getInstance()->executeS(' SELECT id,content FROM ' . _DB_PREFIX_ . 'matable '); function replacePNJ($value) { $value = str_replace('http://www', 'https://www', $value); return $value; } function buildTree(array $elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['parent_id'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } $element['content'] = replacePNJ($element['content']); $branch[] = $element; } } return $branch; } foreach ($aData as $value) { $dataTmp = unserialize($value['content']); $dataTmp = buildTree($dataTmp); $data = serialize($dataTmp); Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'matable SET `content`="' . pSQL($data, true) . '" WHERE id='.$value['id_belvg_productattabs']); }
Leave feedback about this