Outils pour utilisateurs

Outils du site


tips_informatiques:programmation:php:code

Ceci est une ancienne révision du document !


function startWith

    /**
     * Tests if a string starts with a given string
     *
     * @param     string
     * @param     string
     * @return    bool
     */
    function startWith($string, $start)
    {
        return strpos($string, $start) === 0;
    }

function endWith

    /**
     * Tests if a string ends with the given string
     *
     * @param     string
     * @param     string
     * @return    bool
     */
    function endWith($string, $end)
    {
        return strrpos($string, $end) === strlen($string) - strlen($end);
    }

function debug

function debug($object)
{
    echo '<div>';
 
    $calledFrom = debug_backtrace();
    echo '<strong>' . $calledFrom[0]['file'] . '</strong>';
    echo ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
 
    echo('<pre>');
    if(is_array($object))
    {
        print_r($object);
    }
    elseif(is_a($object, 'DOMDocument'))
    {
        $object->formatOutput = true;
        $xml_string = $object->saveXML();
        echo htmlentities($xml_string);
    }
    elseif(is_a($object, 'DOMNodeList'))
    {
        $dom = new DOMDocument();
        $debugElement = $dom->createElement('debug');
        $dom->appendChild($debugElement);
        $object = $dom->importNode($object);
        $debugElement->appendChild($object);
 
        $dom->formatOutput = true;
        $xml_string = $dom->saveXML();
        echo htmlentities($xml_string);
    }
    elseif(is_object($object))
    {
        echo get_class($object);
    }
    else 
    {
        echo $object;
    }
    echo('</pre>');
 
    echo '</div>';
}
tips_informatiques/programmation/php/code.1247479355.txt.gz · Dernière modification: 2009/07/13 00:00 (modification externe)