7
I have a class called Page(page.class.php)
that "mounts" the page, and one of the functions of that class is to censor content by user level.
<?php
class Page(){
//(...)
static function sensurar($str){
$tipoInt = User::tipoInt();
for ($i=0; $i < 11; $i++) {
if ($tipoInt == $i) continue;
$str = Page::clearTag2($str,"<!--a$i-->","<!--$i-->","<!--a-->");
}
return $str;
}
static function clearTag2($str,$tA,$tB,$msg=""){
$str0 = $str;
$pattern = "/({$tA})(.|\n)*({$tB})/";
$str = preg_replace($pattern,$msg,$str);
if (is_null($str)) {echo "erro"; return $str0; };
if($str == "") {
$len = strlen($str0);
$error = preg_last_error();
Page::error("
Limpou a string.
[tA] = '$tA', [tB] = '$tB',[pattern] = '$pattern', [str].length = {$len}
$error
$str0
","Page::clearTag2");
}
return $str;
}
And it was working wonderfully well, until it started to show error. when I use on the page pagina("string")
down below.
<pre><h2>Erro Page::clearTag2</h2>
Limpou a string.
[tA] = '<!--a5-->', [tB] = '<!--5-->',[pattern] = '/(<!--a5-->)(.|
)*(<!--5-->)/', [str].length = 6086
6
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Sistema H |Produto, Odin</title>
<link rel="stylesheet" type="text/css" href="tema.d/oficial.d/css/page.css">
<link rel="stylesheet" type="text/css" href="tema.d/oficial.d/css/menu.css">
<script type="text/javascript">
server = "http://localhost/g2%20soft/ecomerce/";
</script>
<script src="tema.d/oficial.d/js/wrequest.js"></script>
</head>
<body lang="pt-br">
<nav id="menunav">
<header>
<img src="tema.d/oficial.d/img/logo com fundo transparente.png" alt="">
</header>
<ul class="menu">
<li
class="menufechado"
link="perfil"
submenu="true"
>
<span onclick="menuOpen(this)">+ FabricaA[Fabrica]</span>
<ul class="submenu">
<li
class="menufechado"
link="edit_perfil"
submenu="false"
>
<span onclick="menuOpen(this)">Perfil</span>
</li>
<li
class="menufechado"
link="edit_perfil?a=sair"
submenu="false"
>
<span onclick="menuOpen(this)">Sair</span>
</li>
</ul>
</li>
<li
class="menufechado"
link="list_meusprodutos"
submenu="true"
>
<span onclick="menuOpen(this)">+ Produtos</span>
<ul class="submenu">
<li
class="menufechado"
link="list_meusprodutos"
submenu="false"
>
<span onclick="menuOpen(this)">Meus Produtos</span>
</li>
<li
class="menufechado"
link="add_produto"
submenu="false"
>
<span onclick="menuOpen(this)">Cadastrar Produto</span>
</li>
<li
class="menufechado"
link="list_valortipo"
submenu="false"
>
<span onclick="menuOpen(this)">Tabelas de Preço</span>
</li>
</ul>
</li>
<li
class="menufechado"
link="list_meusclientes"
submenu="true"
>
<span onclick="menuOpen(this)">+ Clientes</span>
<ul class="submenu">
<li
class="menufechado"
link="list_meusclientes"
submenu="false"
>
<span onclick="menuOpen(this)">Meus Clientes</span>
</li>
<li
class="menufechado"
link="list_naoclientes"
submenu="false"
>
<span onclick="menuOpen(this)">Não Clientes</span>
</li>
</ul>
</li>
<li
class="menufechado"
link="#"
submenu="true"
>
<span onclick="menuOpen(this)">+ Cadastro</span>
<ul class="submenu">
<li
class="menufechado"
link="add_produto"
submenu="false"
>
<span onclick="menuOpen(this)">Produto</span>
</li>
<li
class="menufechado"
link="add_formadepagamento"
submenu="false"
>
<span onclick="menuOpen(this)">Forma de pagamento</span>
</li>
<li
class="menufechado"
link="add_prasodeentrega"
submenu="false"
>
<span onclick="menuOpen(this)">Praso de pagamento</span>
</li>
</ul>
</li>
<li
class="menufechado"
link="list_pedidosfabrica"
submenu="false"
>
<span onclick="menuOpen(this)">Pedidos</span>
</li>
<li
class="menufechado"
link="mensagens"
submenu="false"
>
<span onclick="menuOpen(this)">Mensagens</span>
</li>
<li
class="menufechado"
link=""
submenu="true"
>
<span onclick="menuOpen(this)">+ Relatorios</span>
<ul class="submenu">
<li
class="menufechado"
link="rela_produtosvendidos"
submenu="false"
>
<span onclick="menuOpen(this)">Produtos Vendidos</span>
</li>
<li
class="menufechado"
link="rela_produtoscadastrados"
submenu="false"
>
<span onclick="menuOpen(this)">Produtos Cadastrados</span>
</li>
<li
class="menufechado"
link="rela_clientescadastrados"
submenu="false"
>
<span onclick="menuOpen(this)">Clientes Cadastrados</span>
</li>
</ul>
</li>
<li
class="menufechado"
link=""
submenu="false"
>
<span onclick="menuOpen(this)">Lançamentos</span>
</li>
</ul>
</nav>
<content>
<h1>Produto, Odin</h1>
<link rel="stylesheet" href="tema.d/oficial.d/css/view_produto.css">
<div class="page_listabas">
<!--a5-->
<div class="page_abalabel " onclick="link('list_loja')">Loja</div>
<!--5-->
<div class="page_abalabel page_abalabel_opened">Ver</div>
<!--a6-->
<div class="page_abalabel" onclick="link('edit_produto?id=52')">Detalhes</div>
<div class="page_abalabel" onclick="link('edit_produtomidia?id=52')">Midias</div>
<!--6-->
</div>
<div class="page_aba">
<div id="referencia">Odin</div>
<div class="midias">
<div class="midia_view">
<img src="anexo\97" alt="midia0" id="midia_view_img">
</div>
<div class="midias_left">
<span> <img src="tema.d/oficial.d/img/midiasview_arrow_left.svg" alt=""> </span>
</div>
<div class="midias_right">
<span> <img src="tema.d/oficial.d/img/midiasview_arrow_right.svg" alt=""> </span>
</div>
<div class="midia_list"><div class="">
<img src="anexo/97" alt="" onclick="setMidia(this)">
</div>
<div class="">
<img src="anexo/98" alt="" onclick="setMidia(this)">
</div>
</div>
</div>
<div class="detalhes">
<p>Odim, tambem conhecido como pai de todos.</p>
<p>
2cx por <valor>R$ 0,00</valor>
</p>
<p>[52]Hidralica Industrial/Eletrica</p>
</div>
<div class="formasdepagamento">
<p>Podendo ser pago:</p>
{{formas de pagamento}}
</div>
<div class="outrosprodutos">
<div class="produto">
<img src="anexo/0" alt="">
</div>
{{outrosprodutos}}
</div>
</div>
<script type="text/javascript" src="tema.d/oficial.d/js/view_produto.js"></script>
<footer>G2</footer>
</content>
<div class="menu-button" onclick="menuShow()">≡</div>
<div class="flutuante" id="flutuante">Loading...</div>
<div class="msgbox_fundo" id="msgbox_fundo" onclick="MSGbox.close()">
<div class="msgbox_box">
<span class="button msgbox_close" onclick="MSGbox.close()">X</span>
<div class="msgbox_conteudo" id="msgbox_conteudo">
</div>
</div>
</div>
<script type="text/javascript" src="tema.d/oficial.d/js/page.js"></script>
<script type="text/javascript" src="tema.d/oficial.d/js/menu.js"></script>
</body>
</html>
I’ve been doing some tests, I think the possible cause of the problem is the expression.
$pattern = "/({$tA})(.|\n)*({$tB})/";
I would guess that there is a character limit that an expression can check.
What is the full, error message?
– Augusto Vasques
There is no (non-native) error message, what happens is that the function preg_replace() returns "null" instead of the "treated" string. but I see no reason to
– IAmMyGod
To documentation says that if the return is NULL then an error has occurred. You can see the return of
preg_last_error()
https://www.php.net/manualen/function.preg-last-error.php– hkotsubo
The error this "almost treated" in the code posted, returns error 6 (PREG_BAD_UTF8_OFSET_ERROR), the problem is: Why? How to solve? or even, if there is another way to do?
– IAmMyGod
In the manual is written >
PREG_BAD_UTF8_OFFSET_ERROR
Returned bypreg_last_error()
if offset did not match the start of a valid UTF-8 code point (only when running a regex in UTF-8 mode).– Augusto Vasques
I don’t understand, you pass all the HTML as a string to the function
sensurar
? What should be the result?– hkotsubo
The file is UTF-8 and must have been saved with BOM. If this is the case, BOM should be removed before being processed by
preg_replace()
– Augusto Vasques
I checked, converted, rewrote files (template). And yet continued the same error.
– IAmMyGod
@Augustovasques Actually Mistake 6 is
PREG_JIT_STACKLIMIT_ERROR
(could not be UTF-8 error because the regex only runs in this mode if it has the flagu
, and in this case it does not). Maybe it is something related to some config in php.ini, because I did some tests and did not give the same error. I’ll do a little more digging and if that’s the case, I’ll give you an answer– hkotsubo