mivita/app/Services/SyS/CleanHTMLProductDescription.php
Kevin Adametz bfa3bb1df4 08 2024
2024-08-05 12:05:24 +02:00

102 lines
3.1 KiB
PHP

<?php
namespace App\Services\SyS;
use App\Models\Product;
use Request;
use App\Models\TransProduct;
use App\Models\UserCreditItem;
class CleanHTMLProductDescription
{
public static function show()
{
dump("CleanHTMLProductDescription");
// dd('check function');
$TransProducts = TransProduct::limit(2000)->get();
dump(count($TransProducts));
$c = 0;
foreach($TransProducts as $item){
if($item->value){
$item->value = self::cleanHTML($item->value);
$item->save();
//dump($item->value);
$c++;
}
}
dump("counter TransProduct");
dump($c);
$Products = Product::limit(2000)->get();
dump(count($Products));
$c = 0;
foreach($Products as $item){
if($item){
$item->copy = self::cleanHTML($item->copy);
$item->description = self::cleanHTML($item->description);
$item->usage = self::cleanHTML($item->usage);
$item->ingredients = self::cleanHTML($item->ingredients);
$item->save();
//dump($item->value);
$c++;
}
}
dump("counter");
dd($c);
}
public static function cleanHTML($html)
{
// $html = preg_replace("/(</?)div/", "$1p", $html);
$html = str_replace('<p> </p>', '', $html);
$html = str_replace('<p></p>', '', $html);
$html = str_replace('<p><br></p>', '', $html);
$html = str_replace('<p><br></p>', '', $html);
$html = str_replace('<br>', '', $html);
$html = str_replace('text -primary', 'text-primary', $html);
$html = str_replace('fa -check', 'fa-check', $html);
$html = str_replace('text- primary', 'text-primary', $html);
$html = str_replace('fa- check', 'fa-check', $html);
$html = str_replace('<ul class="list-unstyled list-icons" style="padding-left: 15px;"> </ul>', '', $html);
$html = str_replace('</span>', '', $html);
$html = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $html);
$html = str_replace('<li></li>', '', $html);
$html = str_replace('<li> </li>', '', $html);
$html = str_replace('< i', '<i', $html);
$html = str_replace('< li>', '<li>', $html);
$html = str_replace('</ i>', '</i>', $html);
$html = str_replace('</ li>', '</li>', $html);
$html = str_replace('</ b>', '</b>', $html);
$html = str_replace('< /b>', '</b>', $html);
$html = str_replace('</ p>', '</p>', $html);
$html = str_replace('< /p>', '</p>', $html);
$html = str_replace('< /i>', '</i>', $html);
$html = str_replace('< /li>', '</li>', $html);
$html = str_replace('<div>', '', $html);
$html = str_replace('</div>', '', $html);
$html = str_replace('>>', '>', $html);
return $html;
}
public static function store()
{
$data = Request::all();
\Session()->flash('alert-save', true);
return back();
}
}