Swap html tags before php Insert

Asked

Viewed 24 times

0

I am creating a function so that HTML tags are changed when doing Insert, and then when retrieving.

I’m doing it properly?

CLASS

class handle
{
  public static function removeTag($target)
  {
    $output = preg_replace("#{~#", "<", $target);
    $output = preg_replace("#~}#", ">", $target);
    $output = preg_replace("#{{q}}#", '"', $target);
    return $output;
 }

  public static function colocaTag($target)
  {
    $output = preg_replace("<", "#{~#", $target);
    $output = preg_replace(">", "#~}#", $target);
    $output = preg_replace('"', "#{{q}}#", $target);
    return $output;
 }
}

When sending to the database:

$comTag = '<p class="important-text">Meu texto com tag </p>';
handle::removeTag($comTag);

Would arrive so in sql

{~p class={{q}}Important-text{{q}}~}My text without tag {~/p~}

Recovering in echo:

$SemTag = '{~p class={{q}}important-text{{q}}~}Meu texto sem tag {~/p~}';
echo handle::colocaTag($SemTag );

<p class="important-text">Meu texto com tag </p>

I’m on the right track?

  • 2

    Maybe this can influence something, so why do you need to do this? There is a limitation/problem in saving HTML in the database?

  • One idea is, instead of using HTML, store a markdown in the bank, then turn the markdown into HTML in the JS frontend

  • @Andersoncarloswoss The idea is to increase protection.

  • Protection against what?

  • @Costamilam markdow, I hadn’t heard of that term.

  • @Andersoncarloswoss I expressed wrong, it is not protection that the bind_param is blocking inserts with tags, so I intend to do something to make it work.

  • @Andersoncarloswoss See https://answall.com/questions/397903/php-bind-param-forbidden

  • Have you made sure that the problem really is between the bind_param and the HTML value?

  • You wear it all the time on Stackoverflow (<= This is a markdown)

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.