V
V
Vladimir2018-02-16 12:22:29
PHP
Vladimir, 2018-02-16 12:22:29

How can I remove html tags from the database using php?

wrote a script:

$result = mysql_query("SELECT * FROM dle_post");
  

  $names = [];
  while ($row = mysql_fetch_array($result)) {
    $names[] = $row['short_story'];
  }
  
  $row1 = mysql_num_rows($result);
  
  for ($i = 0; $i <= $row1; $i++) {
  
  $strop = strip_tags($names[$i]);
  echo $strop;
  $rowok = mysql_query("UPDATE dle_post SET short_story='".$strop."' WHERE short_story='".$names[$i]."'");
  
  }

it removed all html tags for me... BUT!
the following tags are stored in the database: For example , How can I delete them? <p class=\"id1\">

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stimulate, 2018-02-16
@Stimulate

preg_replace('/<([^>]+)>/siu', '', $names[$i]);

N
novrm, 2018-02-16
@novrm

You can peep the implementation in any framework.
For example: Zend\Filter\StripTags

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question