Авторизация
 Регистрация   Войти   Забыли пароль? 

cut_many_tags() PHP-Функция вырезает из HTML ненужные тэги, или другие куски текста, например скрипты от "<SCRIPT" до "</SCRIPT>"

Обновлённый PHP-Fusion Bogatyr / Free CMS PHP-Fusion 7 Bogatyr / PHP-functions for text / cut_many_tags() PHP-Функция вырезает из HTML ненужные тэги, или другие куски текста, например скрипты от "<SCRIPT" до "</SCRIPT>"


 Russian

cut_many_tags() PHP-function cuts out unnecessary tags from HTML, or other pieces of text, for example scripts from "<SCRIPT" to "</ SCRIPT>"

Обновлённый PHP-Fusion Bogatyr / Free CMS PHP-Fusion 7 Bogatyr / PHP-functions for text / cut_many_tags() PHP-function cuts out unnecessary tags from HTML, or other pieces of text, for example scripts from "<SCRIPT" to "</ SCRIPT>"


 English

PHP

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 20

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\mail_bbcode_include.php on line 21

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in F:\OpenServer\domains\php-fusion.vveb.ws\includes\bbcodes\search_bbcode_include.php on line 39
PHP
  1. <?php
  2. // RU:
  3. // вырезает куски текста, например
  4. // скрипты от "<SCRIPT" до "</SCRIPT>"
  5. // комментарии от "<!--" до "-->"
  6. // $del=1 УДАЛЯТЬ ВЫБРАННЫЕ КУСКИ
  7. // $del=0 УДАЛЯТЬ ОСТАЛЬНЫЕ КУСКИ
  8. //  $imp по какому символу имплодить
  9. //  $exp по какому символу эксплодить
  10. // EN:
  11. // cuts out pieces of text, for example
  12. // scripts from "<SCRIPT" to "</ SCRIPT>"
  13. // comments from "<! -" to "->"
  14. // $del=1 DELETE SELECTED CUSKS
  15. // $del=0 REMOVE THE OTHER CUSKS
  16. // $imp on which character to implode()
  17. // $exp by which character to explode()
  18. function cut_tag ($cont, $imp=' ', $exp='    ', $del=1, $cutstart='<script', $cutend='</script>') {
  19.     $cont = str_replace( $exp, ' ', $cont);
  20.     $cont = str_replace($cutstart, $exp.$cutstart, $cont);
  21.     $cont = str_replace($cutend, $cutend.$exp, $cont);
  22.     $arr= explode($exp, $cont);
  23.     $i=0; $new=array();
  24. //    echo "\n<table>";
  25.     while ($i<count($arr)) {
  26.         $cc=0;
  27.          //echo "\n<tr><td>". $i . "</td><td><textarea> " . $arr[$i]."</textarea></td></tr>";
  28.         if (substr($arr[$i], 0, strlen($cutstart))==$cutstart)  $cc=1;
  29.          //if( $del==1 AND $cc==1)  НИЧЕГО !!!!!
  30.         if( $del==1 AND $cc==0)  $new[] = $arr[$i];
  31.         if( $del<>1 AND $cc==1)  $new[] = $arr[$i];
  32.         $i++;
  33.     }
  34.      //echo "\n</table>";
  35.     $cont2 = implode($imp, $new);
  36.     return $cont2;
  37. }
  38. function cut_many_tags ($cont, $imp=' ', $exp='    ', $del=1, $tags=array('script', 'a'), $striptags=1  ) {
  39.     $cont = str_replace( $exp, ' ', $cont);
  40.      // ДОБАВЛЯЮ МЕТКИ ДЛЯ ТЭГОВ ОКРЫВАЮЩИХ
  41.      //$cont = str_replace( '>', '>'.$exp, $cont);
  42.     $cont = str_replace( '<', $exp.'<', $cont);
  43.     $cont = str_replace( $exp.'</', '</', $cont);
  44.     $cont = str_replace( $exp.$exp, $exp, $cont);
  45. //    $cont = str_replace($cutstart, $exp.$cutstart, $cont);
  46. //    $cont = str_replace($cutend, $cutend.$exp, $cont);
  47.     $arr= explode($exp, $cont);
  48.     $i=0; $new=array();
  49. //    echo "\n<table>";
  50. echo "<br> count($"."tags)=".count($tags);
  51.     while ($i<count($arr)) {
  52.         echo "<br>".$i."<textarea  rows='1' cols='70'>".$arr[$i]."</textarea>";
  53.         $cc=0;
  54.         $j=0;
  55.     while ($j<count($tags)) {
  56.          //echo "\n<tr><td>". $i . "</td><td><textarea> " . $arr[$i]."</textarea></td></tr>";
  57.         if (substr($arr[$i], 0, strlen('<'.$tags[$j].' ')) == '<'.$tags[$j].' '
  58.             OR
  59.             substr($arr[$i], 0, strlen('<'.$tags[$j].'>')) == '<'.$tags[$j].'>'  ) { $cc=1; echo " <br> +"; }
  60. echo "<br>".$j." ".$tags[$j]." ". strlen('<'.$tags[$j].' ') . " " . strlen('<'.$tags[$j].'>') ;
  61. echo " <textarea  rows='1' cols='7'>".substr($arr[$i], 0, strlen('<'.$tags[$j].' ')) ."</textarea>";
  62.          //if( $del==1 AND $cc==1)  НИЧЕГО !!!!!
  63.         $j++;
  64.     }
  65.         if ($striptags==1) $arr[$i] = strip_tags($arr[$i]);
  66.         if( $del==1 AND $cc==0)  $new[] = $arr[$i];
  67.         if( $del<>1 AND $cc==1)  $new[] = $arr[$i];
  68.         echo "<hr> <textarea  rows='1' cols='70'>".$arr[$i] ."</textarea>";
  69.         $i++;
  70.     }
  71.      //echo "\n</table>";
  72.     $cont2 = implode($imp, $new);
  73.     return $cont2;
  74. }
  75. // вырезает script, style, comments
  76. // cuts script, style, comments
  77. function cut_script_style_comments ($text ) {
  78.     $text = str_replace(
  79.         array('<SCRIPT', '</SCRIPT', '<STYLE', '</STYLE'),
  80.         array('<script', '</script', '<style', '</style' ),
  81.     $text);
  82.     $text = cut_tag ($text, $imp=' ', $exp='    ', $del=1, $cutstart='<script', $cutend='</script>');
  83.     $text = cut_tag ($text, $imp=' ', $exp='    ', $del=1, $cutstart='<style', $cutend='</style>');
  84.     $text = cut_tag ($text, $imp=' ', $exp='    ', $del=1, $cutstart='<-- ', $cutend='-->');
  85.     $text = cut_tag ($text, $imp=' ', $exp='    ', $del=1, $cutstart='<!-- ', $cutend='-->');
  86.     
  87.     return $text;
  88. }
  89. ?>
Добавить комментарий

Добавить комментарий
Пожалуйста, залогиньтесь для добавления комментария.
Рейтинги
HTML-code and BB-code for blogs and forums

<a href="https://php-fusion.vveb.ws/php-fusion.php?id=67">cut_many_tags() PHP-Функция вырезает из HTML ненужные тэги, или другие куски текста, например скрипты от &quot;&lt;SCRIPT&quot; до &quot;&lt;/SCRIPT&gt;&quot;</a>


[url=https://php-fusion.vveb.ws/php-fusion.php?id=67]cut_many_tags() PHP-Функция вырезает из HTML ненужные тэги, или другие куски текста, например скрипты от &quot;&lt;SCRIPT&quot; до &quot;&lt;/SCRIPT&gt;&quot;[/url]

Language: Default
 
Код для PHP-Fusion