Читает XLSX файл с перечнем мета тэгов и генерирует файл с SQL для обновления метатегов.
Скрипт для составления SQL запросов по XLSX файлу
22.12.2015
01.php (Download)
<??>
<!DOCTYPE HTML>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?
error_reporting(E_ALL);
ini_set('display_errors', 'On');
function conv_obj_UTF_2_1251(&$OBJ)
{
if (is_object($OBJ))
{
$class_vars = get_object_vars($OBJ);
foreach ($class_vars as $name => $value)
{
if (is_string($value))
{
$val = '';
try
{
@$val = iconv("UTF-8", "windows-1251", $value);
}
catch (Exception $e)
{
echo 'Выброшено исключение: ', $e->getMessage(), "\n";
}
if ($val)
{
$OBJ->$name = $val;
// echo 'ok<hr>';
}
}
}
}
else
{
$OBJ = iconv("UTF-8", "windows-1251", $OBJ);
}
return $OBJ;
}
function makeSql($aItem)
{
$sRet = '';
switch ($aItem['type'])
{
case 'aux':
$sRet = '
UPDATE `ab_aux_pages`
SET `meta_title` = \''.$aItem['title'].'\', `meta_description` = \''.$aItem['text'].'\'
WHERE `aux_page_ID`='.$aItem['id']
;
break;
case 'info':
$sRet = '
UPDATE `ab_info_pages`
SET `meta_title` = \''.$aItem['title'].'\', `meta_description` = \''.$aItem['text'].'\'
WHERE `info_page_ID`='.$aItem['id']
;
break;
case 'prod':
$sRet = '
UPDATE `ab_products`
SET `name` = \''.$aItem['title'].'\', `meta_description` = \''.$aItem['text'].'\'
WHERE `productID`='.$aItem['id']
;
break;
case 'cat':
$sRet = '
UPDATE `ab_categories`
SET `adtitle_group` = \''.$aItem['title'].'\', `meta_description` = \''.$aItem['text'].'\'
WHERE `categoryID`='.$aItem['id']
;
break;
default:
break;
}
return $sRet.";\n";
}
function myCut($sIn, $sType)
{
$p0 = strpos($sIn, '-');
$p1 = strpos($sIn, $sType);
$len = strlen($sType);
return substr($sIn, $p1 + $len, $p0 - $p1 - $len);
}
function parseUrl($sIn)
{
$aRet = array();
$aRet['type'] = '';
if(strpos($sIn, 'aux') !== FALSE)
{
$aRet['type'] = 'aux';
}
if(strpos($sIn, 'cat') !== FALSE)
{
$aRet['type'] = 'cat';
}
if(strpos($sIn, 'info') !== FALSE)
{
$aRet['type'] = 'info';
}
if(strpos($sIn, 'prod') !== FALSE)
{
$aRet['type'] = 'prod';
}
if(!$aRet['type'])
{
die('<b>:'. $sIn.' No Type!!!</b>');
}
$aRet['id'] = myCut($sIn, $aRet['type']);
return $aRet;
}
date_default_timezone_set('Europe/Moscow');
require_once ('lib/PHPExcel.php');
$oExcel = PHPExcel_IOFactory::load('in.xlsx');
$sOutFile = 'result.txt';
file_put_contents($sOutFile, '');
?>
<table border="1">
<?
for ($i=1; $i < 344; $i++) // 345
{
$sLink = $oExcel->getActiveSheet()->getCell('A'.$i)->getValue();
$sTitle = $oExcel->getActiveSheet()->getCell('B'.$i)->getValue();
$sTitle = conv_obj_UTF_2_1251($sTitle);
$sText = $oExcel->getActiveSheet()->getCell('C'.$i)->getValue();
$sText = conv_obj_UTF_2_1251($sText);
$aTmp = parseUrl($sLink);
$aTmp['title'] = $sTitle;
$aTmp['text'] = $sText;
if(strpos($aTmp['id'], '_') !== FALSE)
{
continue;
}
$sSql = makeSql($aTmp);
if($sSql)
{
file_put_contents($sOutFile, file_get_contents($sOutFile) . $sSql);
}
?>
<tr>
<td><?=$i;?></td>
<td><?=$sLink;?></td>
<td><?=$aTmp['id'];?></td>
<td><?=$aTmp['type'];?></td>
<?/*
<td><?=$sTitle;?></td>
<td><?=$sText;?></td>
*/?>
</tr>
<?
}
?>
</table>
</body>
</html>
<?
Для работы нужен PHPExcel