Code Duplication    Length = 37-42 lines in 2 locations

class/Utility.php 1 location

@@ 792-833 (lines=42) @@
789
     * @param $document
790
     * @return mixed
791
     */
792
public static function convertHtml2text($document)
793
{
794
    // PHP Manual:: function preg_replace $document should contain an HTML document.
795
        // This will remove HTML tags, javascript sections and white space. It will also
796
        // convert some common HTML entities to their text equivalent.
797
798
        $search = [
799
            "'<script[^>]*?>.*?</script>'si",  // Strip out javascript
800
            "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
801
            "'([\r\n])[\s]+'",                // Strip out white space
802
            "'&(quot|#34);'i",                // Replace HTML entities
803
            "'&(amp|#38);'i",
804
            "'&(lt|#60);'i",
805
            "'&(gt|#62);'i",
806
            "'&(nbsp|#160);'i",
807
            "'&(iexcl|#161);'i",
808
            "'&(cent|#162);'i",
809
            "'&(pound|#163);'i",
810
            "'&(copy|#169);'i"
811
        ];
812
813
    $replace = [
814
            '',
815
            '',
816
            "\\1",
817
            "\"",
818
            '&',
819
            '<',
820
            '>',
821
            ' ',
822
            chr(161),
823
            chr(162),
824
            chr(163),
825
            chr(169)
826
        ];
827
828
    $text = preg_replace($search, $replace, $document);
829
830
    $text = preg_replace_callback("&#(\d+)&", create_function('$matches', "return chr(\$matches[1]);"), $text);
831
832
    return $text;
833
}
834
835
    //Retrieve moduleoptions equivalent to $Xoopsmoduleconfig
836
    /**

include/functions.php 1 location

@@ 525-561 (lines=37) @@
522
}
523
524
// clear descriptions
525
function lx_html2text($document) {
526
    // PHP Manual:: function preg_replace $document should contain an HTML document.
527
    // This will remove HTML tags, javascript sections and white space. It will also
528
    // convert some common HTML entities to their text equivalent.
529
530
    $search       = ["'<script[^>]*?>.*?</script>'si",  // Strip out javascript
531
                     "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
532
                     "'([\r\n])[\s]+'",                // Strip out white space
533
                     "'&(quot|#34);'i",                // Replace HTML entities
534
                     "'&(amp|#38);'i",
535
                     "'&(lt|#60);'i",
536
                     "'&(gt|#62);'i",
537
                     "'&(nbsp|#160);'i",
538
                     "'&(iexcl|#161);'i",
539
                     "'&(cent|#162);'i",
540
                     "'&(pound|#163);'i",
541
                     "'&(copy|#169);'i"];
542
543
    $replace       = ["",
544
                      "",
545
                      "\\1",
546
                      "\"",
547
                      "&",
548
                      "<",
549
                      ">",
550
                      " ",
551
                      chr(161),
552
                      chr(162),
553
                      chr(163),
554
                      chr(169)];
555
556
    $text = preg_replace($search, $replace, $document);
557
558
    $text = preg_replace_callback("&#(\d+)&", create_function('$matches',"return chr(\$matches[1]);"),$text);
559
560
    return $text;
561
}
562
563
//Retrieve moduleoptions equivalent to $Xoopsmoduleconfig
564
function lx_getmoduleoption($option, $repmodule='lexikon') {