Created
January 14, 2016 07:26
-
-
Save vgrish/a2932a2686ad8dbda994 to your computer and use it in GitHub Desktop.
Чистим контент сайта от Рекламнай Сети Яндекса.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$table = $modx->getTableName('modResource'); | |
$sql = "SELECT id,content FROM {$table};"; | |
$stmt = $modx->prepare($sql); | |
$stmt->execute(); | |
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); | |
$sql = ''; | |
$ids = array(); | |
foreach ($rows as $row) { | |
$id = $row['id']; | |
$content = $row['content']; | |
if (preg_match("#<!-- Яндекс.Директ -->#", $content)) { | |
$content = preg_replace("#<!-- Яндекс.Директ -->(.*?)</script>#msi", '', $content); | |
$sql .= "UPDATE {$table} SET `content` = '{$content}' WHERE `id` = '{$id}';"; | |
$ids[] = $id; | |
} | |
} | |
$q = $modx->prepare($sql); | |
$q->execute(); | |
print_r(count($ids)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment