Skip to content

Instantly share code, notes, and snippets.

@suabo
Created November 8, 2018 18:00
Show Gist options
  • Save suabo/33c978511fe9dd9edaf11df3cb2194b0 to your computer and use it in GitHub Desktop.
Save suabo/33c978511fe9dd9edaf11df3cb2194b0 to your computer and use it in GitHub Desktop.
clean article long desc
<?php
/**
* Clean article long descriptions
* Author: Marcel Grolms - suabo
*/
echo "<html><head><meta charset='utf-8' /></head><body>";
include('bootstrap.php');
$oList = oxNew('oxlist');
$oList->init('oxarticle', 'oxarticles');
$oList->selectString('SELECT oxid FROM oxarticles WHERE 1 = 1;');
foreach($oList as $oArticle) {
echo $oArticle->oxarticles__oxid->value . " - ok";
echo "<br />";
$sLongDesc = strip_html_tags($oArticle->getLongDesc());
//echo $sLongDesc;
//echo "<br />";
$oArticle->setArticleLongDesc($sLongDesc);
$oArticle->save();
}
function strip_html_tags($sString) {
$sString = preg_replace(
array(
'@class="[^"]*?"@iu',
'@style="[^"]*?"@iu',
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',
'@</?((address)|(blockquote)|(center)|(del))@iu',
'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
'@</?((table)|(th)|(td)|(caption))@iu',
'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
'@</?((frameset)|(frame)|(iframe))@iu',
'@ @ ',
),
array(
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
"\n\$0",
"\n\$0",
"\n\$0",
"\n\$0",
"\n\$0",
"\n\$0",
"\n\$0",
"\n\$0",
),
$sString);
$sString = preg_replace('/\s+/', ' ', $sString);
$sString = preg_replace('/\s\s+/', ' ', $sString);
$sString=preg_replace("~( +)~"," ",$sString);
$sString=preg_replace("~( +)~"," ",$sString);
return trim(strip_tags($sString, '<p><a><br><h1><h2><h3><h4><h5><h6><b><u><strong>'));
}
echo "</body></html>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment