Code Snippers/PHP: verschil tussen versies

Uit WaaaghPedia
Geen bewerkingssamenvatting
 
Regel 1: Regel 1:
== Print Pre ==
== Print Pre ==


<pre>if ( ! function_exists('print_pre')){
<syntaxhighlight lang="php">if ( ! function_exists('print_pre')){
     /**
     /**
     * Shows print_r in the pre tags
     * Shows print_r in the pre tags
Regel 16: Regel 16:
     }
     }
}
}
</pre>
</syntaxhighlight>


== Var_Pre ==
== Var_Pre ==

Versie van 13 aug 2022 14:37

Print Pre

if ( ! function_exists('print_pre')){
    /**
    * Shows print_r in the pre tags
    * 
    * &#60;pre&#62;print_r($print);&#60;/pre&#62;
    *
    * @param string $print 
    * @return pre string OR No data parsed
    */
    function print_pre($print = 'No data parsed'){
        echo "&#60;pre&#62;";
        print_r($print);
        echo "&#60;/pre&#62;";
    }
}
‎

Var_Pre

if ( ! function_exists('var_pre')){
    /**
    * Shows var_dump in the pre tags
    *
    * <pre>var_dump($dump);</pre>
    *
    * @param string $dump
    * @return pre string OR No data parsed
    */
    function var_pre($dump = 'No data parsed'){
        echo "<pre>";
        var_dump($dump);
        echo "</pre>";
    }
}

XML with CDATA to ARRAY

    $xml = simplexml_load_string($xmlfile, NULL, LIBXML_NOCDATA);
    $json = json_encode($xml, JSON_PRETTY_PRINT);
    $array = json_decode($json, TRUE);
    print_r ($array);