OpenTbs convert html tags to MS Word tags

后端 未结 3 2019
忘了有多久
忘了有多久 2021-01-07 13:55

I am using OpenTbs, http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html.

I have a template.docx and am able to replace fields with content but if th

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 14:06

    Thanks Skrol for your input on all my openTBS issues, just noticed that you are the creator of it, its a great class and what you said above was true after a day of plowing through learning the MS Word Format i had a brain wave and I am now able to produce the format that you specified above and can have bold italic and underline which is all i require, I hope this gives you a foundation to improve upon.

    I basically noticed that in the example you put you just need an array of the styles which when you find a closing tag you remove from the style array. Each time you find a tag you need to close the and create a new one, I have tested it and it works wonderfully.

    class printClass {
        private static $currentStyles = array();    
    
        public function __construct() {}
    
        public function format($string) {
                if($string !=""){
                return preg_replace_callback("#|||||#",
                                            'printClass::replaceTags',
                                            $string);
            }else{
                return false;
            }
        }
    
    
        private static function applyStyles() {
    
            if(count(self::$currentStyles) > 0 ) {
    
                foreach(self::$currentStyles as $value) {
    
                    if($value == "b") {
                        $styles .= "";
                    }   
    
                    if($value == "u") {
                        $styles .= "";
                    }   
    
                    if($value == "i") {
                        $styles .= "";
                    }
                }
    
                return "" . $styles . "";
            }else{
                return false;
            }
        }
    
    
    
        private static function replaceTags($matches) {
    
            if($matches[0] == "") {
                array_push(self::$currentStyles, "b");
            }   
    
            if($matches[0] == "") {
                array_push(self::$currentStyles, "u");
            }   
    
            if($matches[0] == "") {
                array_push(self::$currentStyles, "i");
            }
    
            if($matches[0] == "") {
                self::$currentStyles = array_diff(self::$currentStyles, array("b"));
            }   
    
            if($matches[0] == "") {
                self::$currentStyles = array_diff(self::$currentStyles, array("u"));
            }   
    
            if($matches[0] == "") {
                self::$currentStyles = array_diff(self::$currentStyles, array("i"));
            }
    
            return "" . self::applyStyles() . "";
        }
    }
    

提交回复
热议问题