basic.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 465 行 · 第 1/2 页

PHP
465
字号
        // remove only spaces between > and <        // not the newlines, because this is supposed to be done before in this method        $input = preg_replace('/>(\040)*</U','><',$input);        return $input;    }    /**    *   concatenates short lines, to longer once, reduce number of lines    *   use only as a POST-filter, if you are using 'autoBrace', since it needs the indention    *    *   @version    01/12/16    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param      string  $input  the original template code    *   @return     string  the modified template    */    function concatLines($input)    {// i think i better dont write this filter, since it might be screwy for// <pre> tags, JS and what every else ... think about it// its not done yet anyway/*        $lines = explode("\n",$input);        $output = array();        $curOutputLine = 0;        foreach( $lines as $aLine)        {            // is the line at least 100 characters long?            if( strlen($output[$curOutputLine])>100 )            {                $curOutputLine++;                $output[$curOutputLine] = '';            }            $newLine = trim($aLine);            if(  )            $output[$curOutputLine].= $newLine;        }        return implode("\n",$output);*/    }    /**    *   this places a {if(sizeof($x))} before a {foreach($x as ..)}    *   so i dont have to make this check in every place myself (since i mostly need the    *   check anyway or PHP will freak if $x is an empty array)    *   its just the same as "show a block only if it really contains data"    *   use as a PRE filter    *   out of this:           *    *     {foreach($x as $oneX)}    *         {$oneX}    *     {else}    *         no x's available    *    *   it makes    *    *     {if(sizeof($x))foreach($x as $oneX)}    *         {$oneX}    *     {else}    *         no x's available    *    *   NOTE:   that you can also use {else} on a 'foreach', because it will then be used for the 'if'    *   NOTE1:  this filter can only be applied if the delimiters are not set via the xml    *           options inside the file, this doesnt work yet ... :-(    *           since the xml data change the delimiter, which was passed to the constructor when    *           making an instance of this class    *    *   @version    01/12/11    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param      string  $input  the original template code    *   @return     string  the modified template    */    function addIfBeforeForeach($input)    {        // this i.e. doesnt work with autoBraces off        // {if(...):}  {foreach(...):}{endforeach}{else:}{endif}  ... :-(        if ($this->getOption('autoBraces')==false) {            return $input;        } else {            return preg_replace('/\n(\s*)'.             // get the indented spaces in $1, starting at the beginning of a line (^ didnt work here, at least not for me)                                preg_quote($this->options['delimiter'][0]).                                '\s*foreach\s*\('.    // check for the '{foreach(' and spaces anywhere inbetween, '\s*' does that                                '\s*'.                  // spaces after the '(' might be allowed                                '(\$.*)'.               // get the variable name in $2                                '\s'.                   // and search for the next space, since that means the variable name ended here                                '/U',                   // and be greedy ... dont know why but we need it (i dont understand what greedy means anyway)                                "\n$1".                                $this->options['delimiter'][0].                                "if(is_array(@$2) && sizeof(@$2)>0)foreach($2 ",                                $input);        }    }    /**    *    *    *   @version    01/12/11    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param      string  $input  the original template code    *   @return     string  the modified template    */    function convertEcho($input)    {// FIXXME problem here is if i want to replace {$x} but not {$x=7} with {echo $x}// then i also have to check for $class->property, $a['array'] and so on ... dont know what to do now// i wanted this filter so i dont always have to write { $x=7}, the space is what i need now, so it doesnt get an 'echo' inserted        return preg_replace('/\{\$([a-zA-Z0-9_]*|'.                            '[a-zA-Z0-9_]*->[a-zA-Z0-9_]*\(.*)\}/',"<?=\$$1 ?>",$input);    }    /**    *   applies htmlentites to all the '{$' strings, so the    *   printout will always be valid html    *   do only use as a POST-filter!!    *    *   @version    02/05/13    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param      string  $input  the original template code    *   @return     string  the modified input    */    function applyHtmlEntites($input)    {        return preg_replace( '/(<\?php=|<\?=)\$(.*)\?>/sU' , '<? echo htmlentities($$2)?>' , $input );   //"    }    /**    *   converts &apos; &lt; &gt; &quot; etc. back to normal characters    *   this is needed i.e. if you have an xml-file from Openoffice.org    */    function decodeHtmlEntities( $input )    {           $open = preg_quote($this->getOption('delimiter',0));        $close = preg_quote($this->getOption('delimiter',1));        $transTable = get_html_translation_table(HTML_SPECIALCHARS);        $transTable = array_flip($transTable);        $transTable['&apos;'] = '\'';        // for some reason this reg-exp doesnt find when a closing delimiter is        // right before an opening delimiter i.e. '}{$x[&apos;' strange .. i think i have no idea of regexps :-)        $regExp = "/[^\\\]$open.*[^\\\]$close/Usm";    //"        // so we search just for that what the above dont find        $regExp1 = "/$close$open.*[^\\\]$close/Usm";    //"        // since all the below dont work we use this, this looks like it works :-)        // it also shows how much time+code reg-exps can save (if i was able enough :-( )        preg_match_all($regExp,$input,$res);        $allReplaceables = $res[0];        preg_match_all($regExp1,$input,$res1);        $allReplaceables = array_merge($allReplaceables,$res1[0]);        $allReplaceables = array_unique($allReplaceables);        $replaced = array();        foreach( $allReplaceables as $key=>$aReplaceable )        {            foreach( $transTable as $old=>$new )            {                if( strpos($aReplaceable,$old) !== false )                {                    // we write something in $replaced only when there is something to replace                    // this way we will execute less reg-exps later                    if( !isset($replaced[$key]) )                        $replaced[$key] = $aReplaceable;                    // we only modify the strings in $replaced, so we can simply use the regexp to replace the string later                    // and we still have the origins in $allReplaceables                    $replaced[$key] = str_replace($old,$new,$replaced[$key]);                }            }        }        foreach( $replaced as $key=>$aReplaced )        {                                                                            $input = preg_replace( '/'.preg_quote($allReplaceables[$key]).'/' , $aReplaced , $input );        }/*    this doesnt work, see comment on stripslashes :-(        $input = preg_replace(  //'/([^\\\]'.$open.'.*[^\\\]'.$close.')/Ue',                                //'/([^\\\]{.*[^\\\]})/Use',                                $regExp,                                // its strange that i need stripslashes here, i think                                // this is necessary because a string like 'foo["bar"]' is given as 'foo[\"bar\"]'                                // i dont know why but that's how it is :-( took me some time :-)                                // cant use stripslashes either, since that screws up \{ inside delimiters, and SimpleTag needs that                                "strtr(stripslashes('$0'),\$transTable)",                                $input );*//*  this works on each entry in $transTable but still the problem with stripslashes as described above exists here too :-(        foreach( $transTable as $old=>$new )        {            $regExp = "/[^\\\]$open.*[^\\\]$close/Use";    //"            $input = preg_replace( $regExp , "str_replace(\$old,\$new,stripslashes('$0'))" , $input );        }*/        return $input;    }            /**    *   replace < ?xml by printing them via php, so short_open_tags can be left on    *   since we can not turn it off anyway :-)    *    *   @version    02/11/05    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param      string  $input  the original template code    *   @return     string  the modified template    */    function escapeShortTags( $input )    {        if( ini_get('short_open_tag') )        {                         $input = preg_replace(  '/<\?xml/i',                                    $this->getOption('delimiter',0).' echo "<?xml"'.$this->getOption('delimiter',1),                                    $input);        }        return $input;    }}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?