Last active
May 15, 2022 15:53
-
-
Save zaurmag/3b33192990e8af87ab2e6d8ad67fe2bf to your computer and use it in GitHub Desktop.
Функция добавления кода в статью
This file contains hidden or 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 | |
//отрисовка рекламы в статьях | |
function addContent($addTo, $add, $cntRep, $after = '</p>', $openTag = '<div align="center">', $closeTag = '</div>'){ | |
$posAfter = 0; | |
for ($i=0; $i < $cntRep; $i++) { | |
$pos = stripos($addTo, $after, $posAfter); | |
$posAfter = $pos+strlen($after); | |
if($pos===FALSE){ | |
return $addTo; | |
} | |
} | |
$beforeAdding = substr($addTo, 0, $posAfter); | |
$afterAdding = substr($addTo, $posAfter); | |
$result = $beforeAdding . $openTag . $add . $closeTag . $afterAdding; | |
return $result; | |
} | |
// конец addContent | |
// Пример вставки в статью Joomla | |
$this->item->text = addContent($this->item->text,'<div style="border:3px solid red;color:white;font-size:30px;background:black;">любой код</div>',2); | |
echo $this->item->text; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment