<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:georss="http://www.georss.org/georss"><id>tag:blogger.com,1999:blog-1985129778314828705</id><updated>2009-11-12T08:50:39.551Z</updated><title type="text">PHPEverywhere</title><subtitle type="html">Everything About PHP</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default?start-index=26&amp;max-results=25" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>58</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><link rel="self" href="http://feeds.feedburner.com/Phpeverywhere" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-7484643106757272744</id><published>2008-10-13T14:45:00.003+01:00</published><updated>2008-10-13T17:16:33.627+01:00</updated><title type="text">Create Yahoo! Messenger Image with Own Image</title><content type="html">I already create class for create image like do you want it. &lt;br /&gt;1)You must create folder images then put your image that will be show for your Yahoo Messeger. You must crete 2 image that the image signing your Yahoo Messeger online and offline. Please put your image in folder images. Example offline-smile.png for offline signing and online-smile.png for online signing.&lt;br /&gt;2) Put yahoo.php for call this image. &lt;br /&gt;yahoo.php like below&lt;br /&gt;&amp;lt;?&lt;br /&gt;class ymstatus{&lt;br /&gt; &lt;br /&gt; public function ym_status($id_ym,$filename_suffix){&lt;br /&gt;  &lt;br /&gt;  $fileinfo = pathinfo($filename_suffix);&lt;br /&gt;  $extension = $fileinfo['extension'];&lt;br /&gt;  if($extension == 'jpg') {&lt;br /&gt;   $extension = 'jpeg';&lt;br /&gt;   }&lt;br /&gt;        &lt;br /&gt;  &lt;br /&gt;  $yahoo_url = "http://opi.yahoo.com/online?u=".$id_ym."&amp;m=a&amp;t=1";&lt;br /&gt;  if (ini_get('allow_url_fopen')) {&lt;br /&gt;   error_reporting(0);&lt;br /&gt;   $yahoo = file_get_contents($yahoo_url);&lt;br /&gt;  } elseif(function_exists('curl_init')) {&lt;br /&gt;   $ch = curl_init($yahoo_url);&lt;br /&gt;   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);&lt;br /&gt;   curl_setopt ($ch, CURLOPT_HEADER, 0);&lt;br /&gt;   $yahoo = curl_exec($ch);&lt;br /&gt;   curl_close($ch);&lt;br /&gt;  }&lt;br /&gt;  $yahoo = trim($yahoo);&lt;br /&gt;  if(empty($yahoo)) {&lt;br /&gt;   $imgsrc = "./images/offline-" . $filename_suffix;&lt;br /&gt;  } elseif($yahoo == "01") {&lt;br /&gt;   $imgsrc = "./images/online-" . $filename_suffix;&lt;br /&gt;  } elseif($yahoo == "00") {&lt;br /&gt;   $imgsrc = "./images/offline-" . $filename_suffix;&lt;br /&gt;  } else {&lt;br /&gt;   $imgsrc = "./images/offline-" . $filename_suffix;&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  header("Content-type: image/".$extension);&lt;br /&gt;  readfile($imgsrc);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$ymstatus = new ymstatus();&lt;br /&gt;echo $ymstatus-&gt;ym_status('phpeverywhere','smile2.png');&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;3) you must call this yahoo.php like below for appear images yahoo like do you want it.&lt;br /&gt;&lt;br /&gt;&amp;lt;a href="ymsgr:sendim?phpeverywhere" title="phpeverywhere"&amp;gt;&amp;lt;img src="yahoo.php" alt="" border="0" /&amp;gt;&amp;lt;/a&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-7484643106757272744?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/7484643106757272744/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=1985129778314828705&amp;postID=7484643106757272744" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/7484643106757272744" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/7484643106757272744" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/10/change-yahoo-messenger-image.html" title="Create Yahoo! Messenger Image with Own Image" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-9176924203844505217</id><published>2008-10-10T14:27:00.002+01:00</published><updated>2008-10-10T14:30:23.518+01:00</updated><title type="text">XML  Parse Into Struct</title><content type="html">&amp;lt;?php&lt;br /&gt;$simple = "&lt;para&gt;&lt;note&gt;simple note&lt;/note&gt;&lt;/para&gt;";&lt;br /&gt;$p = xml_parser_create();&lt;br /&gt;xml_parse_into_struct($p, $simple, $vals, $index);&lt;br /&gt;xml_parser_free($p);&lt;br /&gt;echo "Index array\n";&lt;br /&gt;print_r($index);&lt;br /&gt;echo "\nVals array\n";&lt;br /&gt;print_r($vals);&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Index array&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [PARA] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [0] =&gt; 0&lt;br /&gt;            [1] =&gt; 2&lt;br /&gt;        )&lt;br /&gt;    [NOTE] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [0] =&gt; 1&lt;br /&gt;        )&lt;br /&gt;)&lt;br /&gt;Vals array&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;    [0] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [tag] =&gt; PARA&lt;br /&gt;            [type] =&gt; open&lt;br /&gt;            [level] =&gt; 1&lt;br /&gt;        )&lt;br /&gt;    [1] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [tag] =&gt; NOTE&lt;br /&gt;            [type] =&gt; complete&lt;br /&gt;            [level] =&gt; 2&lt;br /&gt;            [value] =&gt; simple note&lt;br /&gt;        )&lt;br /&gt;    [2] =&gt; Array&lt;br /&gt;        (&lt;br /&gt;            [tag] =&gt; PARA&lt;br /&gt;            [type] =&gt; close&lt;br /&gt;            [level] =&gt; 1&lt;br /&gt;        )&lt;br /&gt;)&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-9176924203844505217?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/9176924203844505217/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=1985129778314828705&amp;postID=9176924203844505217" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/9176924203844505217" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/9176924203844505217" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/10/xml-parse-into-struct.html" title="XML  Parse Into Struct" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-3458946607022493442</id><published>2008-09-18T15:00:00.003+01:00</published><updated>2008-09-21T13:11:51.881+01:00</updated><title type="text">XMLParser</title><content type="html">It takes into account array keys with the same name and uses an increment for them instead of overwriting the keys.&lt;br /&gt;&lt;br /&gt;I am using it for SOAP requests (20K - 150K) and it parses very fast compared to PEAR.&lt;br /&gt;&lt;br /&gt;&amp;lt;?&lt;br /&gt;&lt;br /&gt;class XMLParser  {&lt;br /&gt;   &lt;br /&gt;    // raw xml&lt;br /&gt;    private $rawXML;&lt;br /&gt;    // xml parser&lt;br /&gt;    private $parser = null;&lt;br /&gt;    // array returned by the xml parser&lt;br /&gt;    private $valueArray = array();&lt;br /&gt;    private $keyArray = array();&lt;br /&gt;   &lt;br /&gt;    // arrays for dealing with duplicate keys&lt;br /&gt;    private $duplicateKeys = array();&lt;br /&gt;   &lt;br /&gt;    // return data&lt;br /&gt;    private $output = array();&lt;br /&gt;    private $status;&lt;br /&gt;&lt;br /&gt;    public function XMLParser($xml){&lt;br /&gt;        $this-&gt;rawXML = $xml;&lt;br /&gt;        $this-&gt;parser = xml_parser_create();&lt;br /&gt;        return $this-&gt;parse();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private function parse(){&lt;br /&gt;       &lt;br /&gt;        $parser = $this-&gt;parser;&lt;br /&gt;       &lt;br /&gt;        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); // Dont mess with my cAsE sEtTings&lt;br /&gt;        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);     // Dont bother with empty info&lt;br /&gt;        if(!xml_parse_into_struct($parser, $this-&gt;rawXML, $this-&gt;valueArray, $this-&gt;keyArray)){&lt;br /&gt;            $this-&gt;status = 'error: '.xml_error_string(xml_get_error_code($parser)).' at line '.xml_get_current_line_number($parser);&lt;br /&gt;            return false;&lt;br /&gt;        }&lt;br /&gt;        xml_parser_free($parser);&lt;br /&gt;&lt;br /&gt;        $this-&gt;findDuplicateKeys();&lt;br /&gt;&lt;br /&gt;        // tmp array used for stacking&lt;br /&gt;        $stack = array();        &lt;br /&gt;        $increment = 0;&lt;br /&gt;       &lt;br /&gt;        foreach($this-&gt;valueArray as $val) {&lt;br /&gt;            if($val['type'] == "open") {&lt;br /&gt;                //if array key is duplicate then send in increment&lt;br /&gt;                if(array_key_exists($val['tag'], $this-&gt;duplicateKeys)){&lt;br /&gt;                    array_push($stack, $this-&gt;duplicateKeys[$val['tag']]);&lt;br /&gt;                    $this-&gt;duplicateKeys[$val['tag']]++;&lt;br /&gt;                }&lt;br /&gt;                else{&lt;br /&gt;                    // else send in tag&lt;br /&gt;                    array_push($stack, $val['tag']);&lt;br /&gt;                }&lt;br /&gt;            } elseif($val['type'] == "close") {&lt;br /&gt;                array_pop($stack);&lt;br /&gt;                // reset the increment if they tag does not exists in the stack&lt;br /&gt;                if(array_key_exists($val['tag'], $stack)){&lt;br /&gt;                    $this-&gt;duplicateKeys[$val['tag']] = 0;&lt;br /&gt;                }&lt;br /&gt;            } elseif($val['type'] == "complete") {&lt;br /&gt;                //if array key is duplicate then send in increment&lt;br /&gt;                if(array_key_exists($val['tag'], $this-&gt;duplicateKeys)){&lt;br /&gt;                    array_push($stack, $this-&gt;duplicateKeys[$val['tag']]);&lt;br /&gt;                    $this-&gt;duplicateKeys[$val['tag']]++;&lt;br /&gt;                }&lt;br /&gt;                else{               &lt;br /&gt;                    // else send in tag&lt;br /&gt;                    array_push($stack,  $val['tag']);&lt;br /&gt;                }&lt;br /&gt;                $this-&gt;setArrayValue($this-&gt;output, $stack, $val['value']);&lt;br /&gt;                array_pop($stack);&lt;br /&gt;            }&lt;br /&gt;            $increment++;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        $this-&gt;status = 'success: xml was parsed';&lt;br /&gt;        return true;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    private function findDuplicateKeys(){&lt;br /&gt;       &lt;br /&gt;        for($i=0;$i &lt; count($this-&gt;valueArray); $i++) {&lt;br /&gt;            // duplicate keys are when two complete tags are side by side&lt;br /&gt;            if($this-&gt;valueArray[$i]['type'] == "complete"){&lt;br /&gt;                if( $i+1 &lt; count($this-&gt;valueArray) ){&lt;br /&gt;                    if($this-&gt;valueArray[$i+1]['tag'] == $this-&gt;valueArray[$i]['tag'] &amp;&amp; $this-&gt;valueArray[$i+1]['type'] == "complete"){&lt;br /&gt;                        $this-&gt;duplicateKeys[$this-&gt;valueArray[$i]['tag']] = 0;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            // also when a close tag is before an open tag and the tags are the same&lt;br /&gt;            if($this-&gt;valueArray[$i]['type'] == "close"){&lt;br /&gt;                if( $i+1 &lt; count($this-&gt;valueArray) ){&lt;br /&gt;                    if(    $this-&gt;valueArray[$i+1]['type'] == "open" &amp;&amp; $this-&gt;valueArray[$i+1]['tag'] == $this-&gt;valueArray[$i]['tag'])&lt;br /&gt;                        $this-&gt;duplicateKeys[$this-&gt;valueArray[$i]['tag']] = 0;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;           &lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    private function setArrayValue(&amp;$array, $stack, $value){&lt;br /&gt;        if ($stack) {&lt;br /&gt;            $key = array_shift($stack);&lt;br /&gt;            $this-&gt;setArrayValue($array[$key], $stack, $value);&lt;br /&gt;            return $array;&lt;br /&gt;        } else {&lt;br /&gt;            $array = $value;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public function getOutput(){&lt;br /&gt;        return $this-&gt;output;&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    public function getStatus(){&lt;br /&gt;        return $this-&gt;status;   &lt;br /&gt;    }&lt;br /&gt;      &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?gt&amp;;&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;br /&gt;$p = new XMLParser($xml);&lt;br /&gt;$p-&gt;getOutput();&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-3458946607022493442?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="related" href="http://phpeverywhere.blogspot.com/2008/09/xmlparser.html" title="XMLParser" /><link rel="enclosure" type="text/html" href="http://phpeverywhere.blogspot.com/2008/09/xmlparser.html" length="0" /><link rel="replies" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/3458946607022493442/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=1985129778314828705&amp;postID=3458946607022493442" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/3458946607022493442" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/3458946607022493442" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/09/xmlparser.html" title="XMLParser" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-6589160346640533335</id><published>2008-09-18T15:00:00.001+01:00</published><updated>2008-09-18T15:00:52.850+01:00</updated><title type="text">parsemoldb.php - parses moldb.xml into an array of molecular objects</title><content type="html">&amp;lt;?php&lt;br /&gt;&lt;br /&gt;class AminoAcid {&lt;br /&gt;    var $name;  // aa name&lt;br /&gt;    var $symbol;    // three letter symbol&lt;br /&gt;    var $code;  // one letter code&lt;br /&gt;    var $type;  // hydrophobic, charged or neutral&lt;br /&gt;    &lt;br /&gt;    function AminoAcid ($aa) &lt;br /&gt;    {&lt;br /&gt;        foreach ($aa as $k=&gt;$v)&lt;br /&gt;            $this-&gt;$k = $aa[$k];&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function readDatabase($filename) &lt;br /&gt;{&lt;br /&gt;    // read the XML database of aminoacids&lt;br /&gt;    $data = implode("", file($filename));&lt;br /&gt;    $parser = xml_parser_create();&lt;br /&gt;    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);&lt;br /&gt;    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);&lt;br /&gt;    xml_parse_into_struct($parser, $data, $values, $tags);&lt;br /&gt;    xml_parser_free($parser);&lt;br /&gt;&lt;br /&gt;    // loop through the structures&lt;br /&gt;    foreach ($tags as $key=&gt;$val) {&lt;br /&gt;        if ($key == "molecule") {&lt;br /&gt;            $molranges = $val;&lt;br /&gt;            // each contiguous pair of array entries are the &lt;br /&gt;            // lower and upper range for each molecule definition&lt;br /&gt;            for ($i=0; $i &lt; count($molranges); $i+=2) {&lt;br /&gt;                $offset = $molranges[$i] + 1;&lt;br /&gt;                $len = $molranges[$i + 1] - $offset;&lt;br /&gt;                $tdb[] = parseMol(array_slice($values, $offset, $len));&lt;br /&gt;            }&lt;br /&gt;        } else {&lt;br /&gt;            continue;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return $tdb;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function parseMol($mvalues) &lt;br /&gt;{&lt;br /&gt;    for ($i=0; $i &lt; count($mvalues); $i++) {&lt;br /&gt;        $mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];&lt;br /&gt;    }&lt;br /&gt;    return new AminoAcid($mol);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$db = readDatabase("moldb.xml");&lt;br /&gt;echo "** Database of AminoAcid objects:\n";&lt;br /&gt;print_r($db);&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-6589160346640533335?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/6589160346640533335/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=1985129778314828705&amp;postID=6589160346640533335" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/6589160346640533335" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/6589160346640533335" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/09/parsemoldbphp-parses-moldbxml-into.html" title="parsemoldb.php - parses moldb.xml into an array of molecular objects" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-2663458581536941220</id><published>2008-09-14T19:37:00.001+01:00</published><updated>2008-09-14T20:06:31.833+01:00</updated><title type="text">Get to All The CDATA</title><content type="html">&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function printCDATA($pItem)&lt;br /&gt;{&lt;br /&gt;  foreach($pItem as $value){&lt;br /&gt;    if (isset($value[children])){&lt;br /&gt;      printCDATA($value[children]); &lt;br /&gt;    }else{&lt;br /&gt;      if(isset($value[name])){&lt;br /&gt;        echo $value[name].": "; &lt;br /&gt;      }&lt;br /&gt;      if(isset($value[cdata])){&lt;br /&gt;        echo $value[cdata]."&lt;br&gt;"; &lt;br /&gt;      }&lt;br /&gt;    } &lt;br /&gt;  }  &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;printCDATA($stack);&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-2663458581536941220?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/2663458581536941220/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=1985129778314828705&amp;postID=2663458581536941220" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/2663458581536941220" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/2663458581536941220" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/09/get-to-all-cdata.html" title="Get to All The CDATA" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-4268747133359078594</id><published>2008-09-14T19:31:00.003+01:00</published><updated>2008-09-14T19:35:14.314+01:00</updated><title type="text">xml_parse</title><content type="html">This is a follow up to the parser class posted by neoyahuu at yahoo dot com. The xml_set_character_data_handler function falls prey to the weird splitting caused by special characters (i.e. new lines whenever an umlaut is found) - my fix just uses concatenation to stop this from happening. This is a great function otherwise. The code:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;class xx_xml {&lt;br /&gt;&lt;br /&gt;    // XML parser variables&lt;br /&gt;    var $parser;&lt;br /&gt;    var $name;&lt;br /&gt;    var $attr;&lt;br /&gt;    var $data  = array();&lt;br /&gt;    var $stack = array();&lt;br /&gt;    var $keys;&lt;br /&gt;    var $path;&lt;br /&gt;   &lt;br /&gt;    // either you pass url atau contents.&lt;br /&gt;    // Use 'url' or 'contents' for the parameter&lt;br /&gt;    var $type;&lt;br /&gt;&lt;br /&gt;    // function with the default parameter value&lt;br /&gt;    function xx_xml($url='http://www.opocot.com', $type='url') {&lt;br /&gt;        $this-&gt;type = $type;&lt;br /&gt;        $this-&gt;url  = $url;&lt;br /&gt;        $this-&gt;parse();&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    // parse XML data&lt;br /&gt;    function parse()&lt;br /&gt;    {&lt;br /&gt;        $data = '';&lt;br /&gt;        $this-&gt;parser = xml_parser_create ("UTF-8");&lt;br /&gt;        xml_set_object($this-&gt;parser, $this);&lt;br /&gt;        xml_set_element_handler($this-&gt;parser, 'startXML', 'endXML');&lt;br /&gt;        xml_set_character_data_handler($this-&gt;parser, 'charXML');&lt;br /&gt;&lt;br /&gt;        xml_parser_set_option($this-&gt;parser, XML_OPTION_CASE_FOLDING, false);&lt;br /&gt;&lt;br /&gt;        if ($this-&gt;type == 'url') {&lt;br /&gt;            // if use type = 'url' now we open the XML with fopen&lt;br /&gt;           &lt;br /&gt;            if (!($fp = @fopen($this-&gt;url, 'rb'))) {&lt;br /&gt;                $this-&gt;error("Cannot open {$this-&gt;url}");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            while (($data = fread($fp, 8192))) {&lt;br /&gt;                if (!xml_parse($this-&gt;parser, $data, feof($fp))) {&lt;br /&gt;                    $this-&gt;error(sprintf('XML error at line %d column %d',&lt;br /&gt;                    xml_get_current_line_number($this-&gt;parser),&lt;br /&gt;                    xml_get_current_column_number($this-&gt;parser)));&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        } else if ($this-&gt;type == 'contents') {&lt;br /&gt;            // Now we can pass the contents, maybe if you want&lt;br /&gt;            // to use CURL, SOCK or other method.&lt;br /&gt;            $lines = explode("\n",$this-&gt;url);&lt;br /&gt;            foreach ($lines as $val) {&lt;br /&gt;                if (trim($val) == '')&lt;br /&gt;                    continue;&lt;br /&gt;                $data = $val . "\n";&lt;br /&gt;                if (!xml_parse($this-&gt;parser, $data)) {&lt;br /&gt;                    echo $data.'&lt;br /&gt;';&lt;br /&gt;                    $this-&gt;error(sprintf('XML error at line %d column %d',&lt;br /&gt;                    xml_get_current_line_number($this-&gt;parser),&lt;br /&gt;                    xml_get_current_column_number($this-&gt;parser)));&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    function startXML($parser, $name, $attr)    {&lt;br /&gt;        $this-&gt;stack[$name] = array();&lt;br /&gt;        $keys = '';&lt;br /&gt;        $total = count($this-&gt;stack)-1;&lt;br /&gt;        $i=0;&lt;br /&gt;        foreach ($this-&gt;stack as $key =&gt; $val)    {&lt;br /&gt;            if (count($this-&gt;stack) &gt; 1) {&lt;br /&gt;                if ($total == $i)&lt;br /&gt;                    $keys .= $key;&lt;br /&gt;                else&lt;br /&gt;                    $keys .= $key . '|'; // The saparator&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;                $keys .= $key;&lt;br /&gt;            $i++;&lt;br /&gt;        }&lt;br /&gt;        if (array_key_exists($keys, $this-&gt;data))    {&lt;br /&gt;            $this-&gt;data[$keys][] = $attr;&lt;br /&gt;        }    else&lt;br /&gt;            $this-&gt;data[$keys] = $attr;&lt;br /&gt;        $this-&gt;keys = $keys;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    function endXML($parser, $name)    {&lt;br /&gt;        end($this-&gt;stack);&lt;br /&gt;        if (key($this-&gt;stack) == $name)&lt;br /&gt;            array_pop($this-&gt;stack);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    function charXML($parser, $data)    {&lt;br /&gt;        if (trim($data) != '')&lt;br /&gt;            @$startFrom = count($this-&gt;data[$this-&gt;keys])-1; // fixes weird splitting (bug?)&lt;br /&gt;            @$startFrom = $startFrom == -1 ? $startFrom = 0 : $startFrom;&lt;br /&gt;            @$this-&gt;data[$this-&gt;keys]['data'][$startFrom] .= trim(str_replace("\n", '', $data));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    function error($msg)    {&lt;br /&gt;        echo "&lt;div align=\"center\"&gt;&lt;br /&gt;            &lt;font color=\"red\"&gt;&lt;b&gt;Error: $msg&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;            &lt;/div&gt;";&lt;br /&gt;        exit();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-4268747133359078594?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="related" href="http://id2.php.net/manual/en/function.xml-parse.php" title="xml_parse" /><link rel="replies" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/4268747133359078594/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=1985129778314828705&amp;postID=4268747133359078594" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4268747133359078594" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4268747133359078594" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/09/this-is-follow-up-to-parser-class.html" title="xml_parse" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-103494222074872750</id><published>2008-09-12T06:32:00.001+01:00</published><updated>2008-09-14T19:30:46.067+01:00</updated><title type="text">Map XML to HTML</title><content type="html">&lt;div&gt;&lt;br /&gt;  &lt;div&gt; &amp;lt;?php&lt;br&gt;&lt;br /&gt;    $file = "data.xml";&lt;br&gt;&lt;br /&gt;    $map_array = array(&lt;br&gt;&lt;br /&gt;    "BOLD"     =&amp;gt; "B",&lt;br&gt;&lt;br /&gt;    "EMPHASIS" =&amp;gt; "I",&lt;br&gt;&lt;br /&gt;    "LITERAL"  =&amp;gt; "TT"&lt;br&gt;&lt;br /&gt;    );&lt;br&gt;&lt;br /&gt;    &lt;br&gt;&lt;br /&gt;    function startElement($parser, $name, $attrs) &lt;br&gt;&lt;br /&gt;    {&lt;br&gt;&lt;br /&gt;    &lt;br /&gt;global $map_array;    &lt;br&gt;&lt;br /&gt;if (isset($map_array[$name])) {    &lt;br&gt;&lt;br /&gt;echo     "&amp;lt;$map_array[$name]&amp;gt;";&lt;br&gt;&lt;br /&gt;}    &lt;br&gt;&lt;br /&gt;    }&lt;br&gt;&lt;br /&gt;    &lt;br&gt;&lt;br /&gt;    function endElement($parser, $name) &lt;br&gt;&lt;br /&gt;    {&lt;br&gt;&lt;br /&gt;global $map_array;    &lt;br&gt;&lt;br /&gt;if (isset($map_array[$name])) {    &lt;br&gt;     &lt;br /&gt;echo     "&amp;lt;/$map_array[$name]&amp;gt;";&lt;br&gt;&lt;br /&gt;}    &lt;br&gt;&lt;br /&gt;    }&lt;br&gt;&lt;br /&gt;    &lt;br&gt;&lt;br /&gt;    function characterData($parser, $data) &lt;br&gt;&lt;br /&gt;    {&lt;br&gt;&lt;br /&gt;echo $data;    &lt;br&gt;&lt;br /&gt;    }&lt;br&gt;&lt;br /&gt;    &lt;br&gt;&lt;br /&gt;    $xml_parser = xml_parser_create();&lt;br&gt;&lt;br /&gt;    // use case-folding so we are sure to find the tag in $map_array&lt;br&gt;&lt;br /&gt;    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);&lt;br&gt;&lt;br /&gt;    xml_set_element_handler($xml_parser, "startElement", "endElement");&lt;br&gt;&lt;br /&gt;    xml_set_character_data_handler($xml_parser, "characterData");&lt;br&gt;&lt;br /&gt;    if (!($fp = fopen($file, "r"))) {&lt;br&gt;&lt;br /&gt;die(    "could not open XML input");&lt;br&gt;&lt;br /&gt;    }&lt;br&gt;&lt;br /&gt;    &lt;br&gt;&lt;br /&gt;    while ($data = fread($fp, 4096)) {&lt;br&gt;&lt;br /&gt;if (!xml_parse($xml_parser, $data, feof($fp))) {    &lt;br&gt;&lt;br /&gt;die(sprintf(    "XML error: %s at line %d",&lt;br&gt;&lt;br /&gt;xml_error_string(xml_get_error_code($xml_parser)),    &lt;br&gt;&lt;br /&gt;xml_get_current_line_number($xml_parser)));    &lt;br&gt;&lt;br /&gt;}    &lt;br&gt;&lt;br /&gt;    }&lt;br&gt;&lt;br /&gt;    xml_parser_free($xml_parser);&lt;br&gt;&lt;br /&gt;    ?&amp;gt; &lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-103494222074872750?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://phpeverywhere.blogspot.com/feeds/103494222074872750/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=1985129778314828705&amp;postID=103494222074872750" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/103494222074872750" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/103494222074872750" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/09/map-xml-to-html.html" title="Map XML to HTML" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-4708837161684031563</id><published>2008-01-05T02:10:00.000Z</published><updated>2008-01-05T02:13:44.136Z</updated><title type="text">Calculate The Sha1 Hash Of A String</title><content type="html">So far as the dictionary attacks are concerned, I thought up the following function:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;function twistSTR($array){&lt;br /&gt;  $twisted="";&lt;br /&gt;  $array_strlen=array();&lt;br /&gt;&lt;br /&gt;  foreach ($array as $element){&lt;br /&gt;    $array_strlen[]=strlen($element);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  for ($i=0; $i&amp;lt;max($array_strlen); $i++){&lt;br /&gt;    foreach ($array as $element){&lt;br /&gt;      if ($i&amp;lt;strlen($element)){&lt;br /&gt;        $twisted=$twisted.$element{$i};&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  return $twisted;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;The twistSTR function basically takes an array input of strings and alternates each character of each string among all the other strings.  For example:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;echo twistSTR(array("this","and","that"));//output: tathnhidast&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;It can be applied in the following manner:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if ($un===$_POST["username"] &amp;&amp; $pwd===sha1(twistSTR(array($salt,$_POST["password"])))){&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;It's not amazingly difficult to reverse engineer the actual output, but then again, that's not the point.  The point is that when a password is entered into one of those databases, they are going to enter for example "thisandthat", not "tathnhidast".&lt;br /&gt;&lt;br /&gt;For all the php4 users who thought you were limited to sha1.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$phrase = "Hello World";&lt;br /&gt;&lt;br /&gt;$sha1a =  base64_encode(sha1($phrase));&lt;br /&gt;$sha1b =  base64_encode(bin2hex(mhash(MHASH_SHA1,$phrase)));&lt;br /&gt;$sha256b= base64_encode(bin2hex(mhash(MHASH_SHA256,$phrase)));&lt;br /&gt;&lt;br /&gt;echo ("SHA1..:" . $sha1a . "\n");&lt;br /&gt;echo ("SHA1..:" . $sha1b . "\n");&lt;br /&gt;echo ("SHA256:" . $sha256b . "\n");&lt;br /&gt;?&amp;gt;&lt;br /&gt;# php sha.php&lt;br /&gt;SHA1..:MGE0ZDU1YThkNzc4ZTUwMjJmYWI3MDE5NzdjNWQ4NDBiYmM0ODZkMA==&lt;br /&gt;SHA1..:MGE0ZDU1YThkNzc4ZTUwMjJmYWI3MDE5NzdjNWQ4NDBiYmM0ODZkMA==&lt;br /&gt;SHA256:YTU5MWE2ZDQwYmY0MjA0MDRhMDExNzMzY2ZiN2IxOTBkNjJjNjV...........&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-4708837161684031563?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4708837161684031563" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4708837161684031563" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2008/01/calculate-sha1-hash-of-string.html" title="Calculate The Sha1 Hash Of A String" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-8033712588786658794</id><published>2007-12-26T08:56:00.000Z</published><updated>2007-12-26T08:57:15.688Z</updated><title type="text">Absolute Value</title><content type="html">Let's say you are resizing images to a standard size that can be expressed as a ratio (width/height). The problem I came into was that I wanted to be reasonable with the proportion of the images that my customer is uploading (couldn't we all use a little less horizontal on pictures?), but I wanted to reject the horizontal pictures when they were uploading vertical ones. So I wanted to accept proportions of images that were within a reasonable threshold (+ or -) of what I will be resizing them to.&lt;br /&gt;&lt;br /&gt;Assuming a standard of 1 to 4 (0.25) and a threshold of no more than 0.05 deviation, then the number 0.30 and 0.20 would return true and 0.19 would return false.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function threshold($given,$thresh,$standard)&lt;br /&gt;{&lt;br /&gt;     return (abs($given-$standard)&lt;=$thresh) ? true : false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;other example&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$abs = abs(-4.2); // $abs = 4.2; (double/float)&lt;br /&gt;$abs2 = abs(5);   // $abs2 = 5; (integer)&lt;br /&gt;$abs3 = abs(-5);  // $abs3 = 5; (integer)&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-8033712588786658794?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8033712588786658794" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8033712588786658794" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/absolute-value.html" title="Absolute Value" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-8864032414279183434</id><published>2007-12-26T08:54:00.000Z</published><updated>2007-12-26T08:55:35.570Z</updated><title type="text">Arc Cosine</title><content type="html">To calculate an angle from a triangle's sides.&lt;br /&gt;&lt;br /&gt;Use the 'law of cosines' :&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;//        a²+b²-c²           &lt;br /&gt;// cosC = --------&lt;br /&gt;//           2ab&lt;br /&gt;&lt;br /&gt;function calculateAngle($c,$a,$b)&lt;br /&gt;{&lt;br /&gt;    $angleInRadians=acos((pow($a,2) + pow($b,2) - pow($c,2)) / (2 * $a * $b));&lt;br /&gt;    return rad2deg($angleInRadians);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;$a, $b, $c are the triangle sides.&lt;br /&gt;&lt;br /&gt;The function returns the angle opposite side c, in degrees.&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-8864032414279183434?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8864032414279183434" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8864032414279183434" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/arc-cosine.html" title="Arc Cosine" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-358904315863437383</id><published>2007-12-26T00:32:00.001Z</published><updated>2007-12-26T00:32:39.174Z</updated><title type="text">Regular Expression</title><content type="html">&amp;lt;?php&lt;br /&gt;// Returns true if "abc" is found anywhere in $string.&lt;br /&gt;ereg("abc", $string);            &lt;br /&gt;&lt;br /&gt;// Returns true if "abc" is found at the beginning of $string.&lt;br /&gt;ereg("^abc", $string);&lt;br /&gt;&lt;br /&gt;// Returns true if "abc" is found at the end of $string.&lt;br /&gt;ereg("abc$", $string);&lt;br /&gt;&lt;br /&gt;// Returns true if client browser is Netscape 2, 3 or MSIE 3.&lt;br /&gt;eregi("(ozilla.[23]|MSIE.3)", $_SERVER["HTTP_USER_AGENT"]);&lt;br /&gt;&lt;br /&gt;// Places three space separated words into $regs[1], $regs[2] and $regs[3].&lt;br /&gt;ereg("([[:alnum:]]+) ([[:alnum:]]+) ([[:alnum:]]+)", $string, $regs); &lt;br /&gt;&lt;br /&gt;// Put a &lt;br /&gt; tag at the beginning of $string.&lt;br /&gt;$string = ereg_replace("^", "&lt;br /&gt;", $string); &lt;br /&gt; &lt;br /&gt;// Put a &lt;br /&gt; tag at the end of $string.&lt;br /&gt;$string = ereg_replace("$", "&lt;br /&gt;", $string); &lt;br /&gt;&lt;br /&gt;// Get rid of any newline characters in $string.&lt;br /&gt;$string = ereg_replace("\n", "", $string);&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-358904315863437383?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/358904315863437383" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/358904315863437383" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/regular-expression.html" title="Regular Expression" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-5370722397474512749</id><published>2007-12-26T00:30:00.000Z</published><updated>2007-12-26T00:31:41.491Z</updated><title type="text">Get The Uptime And Display It In A Message Box</title><content type="html">&amp;lt;?php&lt;br /&gt;// Define constants needed, taken from&lt;br /&gt;// Visual Studio/Tools/Winapi/WIN32API.txt&lt;br /&gt;define("MB_OK", 0);&lt;br /&gt;&lt;br /&gt;// Load the extension in&lt;br /&gt;dl("php_w32api.dll");&lt;br /&gt;&lt;br /&gt;// Register the GetTickCount function from kernel32.dll&lt;br /&gt;w32api_register_function("kernel32.dll", &lt;br /&gt;                         "GetTickCount",&lt;br /&gt;                         "long");&lt;br /&gt;                         &lt;br /&gt;// Register the MessageBoxA function from User32.dll&lt;br /&gt;w32api_register_function("User32.dll",&lt;br /&gt;                         "MessageBoxA",&lt;br /&gt;                         "long");&lt;br /&gt;&lt;br /&gt;// Get uptime information&lt;br /&gt;$ticks = GetTickCount();&lt;br /&gt;&lt;br /&gt;// Convert it to a nicely displayable text&lt;br /&gt;$secs  = floor($ticks / 1000);&lt;br /&gt;$mins  = floor($secs / 60);&lt;br /&gt;$hours = floor($mins / 60);&lt;br /&gt;&lt;br /&gt;$str = sprintf("You have been using your computer for:" .&lt;br /&gt;                "\r\n %d Milliseconds, or \r\n %d Seconds" .&lt;br /&gt;                "or \r\n %d mins or\r\n %d hours %d mins.",&lt;br /&gt;                $ticks,&lt;br /&gt;                $secs,&lt;br /&gt;                $mins,&lt;br /&gt;                $hours,&lt;br /&gt;                $mins - ($hours*60));&lt;br /&gt;&lt;br /&gt;// Display a message box with only an OK button and the uptime text&lt;br /&gt;MessageBoxA(NULL, &lt;br /&gt;            $str, &lt;br /&gt;            "Uptime Information", &lt;br /&gt;            MB_OK);&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-5370722397474512749?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5370722397474512749" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5370722397474512749" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/get-uptime-and-display-it-in-message.html" title="Get The Uptime And Display It In A Message Box" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-5301586911316130044</id><published>2007-12-25T14:55:00.001Z</published><updated>2007-12-25T14:55:49.018Z</updated><title type="text">Tells Whether The Filename Is A Symbolic Link</title><content type="html">On Mac OSX, to see if a file is a FInder alias:&lt;br /&gt;&lt;br /&gt;&amp;lt;?PHP&lt;br /&gt;if( getFinderAlias( $someFile , $target ) ) {&lt;br /&gt; echo $target;&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt; echo "File is not an alias";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function getFinderAlias( $filename , &amp;$target ) {&lt;br /&gt;$getAliasTarget = &lt;&lt;&lt; HEREDOC&lt;br /&gt;    -- BEGIN APPLESCRIPT --&lt;br /&gt;    set checkFileStr to "{$filename}"&lt;br /&gt;    set checkFile to checkFileStr as POSIX file&lt;br /&gt;    try&lt;br /&gt;        tell application "Finder"&lt;br /&gt;            if original item of file checkFile exists then&lt;br /&gt;                set targetFile to (original item of file checkFile) as alias&lt;br /&gt;                set posTargetFile to POSIX path of targetFile as text&lt;br /&gt;                get posTargetFile&lt;br /&gt;            end if&lt;br /&gt;        end tell&lt;br /&gt;    end try&lt;br /&gt;    -- END APPLESCRIPT --&lt;br /&gt;HEREDOC;&lt;br /&gt;$runText = "osascript &lt;&lt; EOS\n{$getAliasTarget}\nEOS\n";&lt;br /&gt;$target = trim( shell_exec( $runText ) );&lt;br /&gt;return ( $target == "" ? false : true );&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-5301586911316130044?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5301586911316130044" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5301586911316130044" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/tells-whether-filename-is-symbolic-link.html" title="Tells Whether The Filename Is A Symbolic Link" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-8916455302646257439</id><published>2007-12-25T14:53:00.000Z</published><updated>2007-12-25T14:54:29.622Z</updated><title type="text">Creates A Symbolic Link</title><content type="html">Windows Vista has its own symlink program now (mklink). Hopefully future versions of PHP for Windows will have this function put it?&lt;br /&gt;&lt;br /&gt;Anyway, this will work on Vista (assuming your PHP user has the proper permissions):&lt;br /&gt;&amp;lt;?php&lt;br /&gt;define('SYMLINK_FILE', 0);&lt;br /&gt;define('SYMLINK_DIR', 1);&lt;br /&gt;define('SYMLINK_JUNCTION', 2);&lt;br /&gt;function symlink ($target, $link, $flag = SYMLINK_FILE) {&lt;br /&gt;    switch ($flag) {&lt;br /&gt;       case SYMLINK_DIR: $pswitch = '/d'; break;&lt;br /&gt;       case SYMLINK_JUNCTION: $pswitch = '/j'; break;&lt;br /&gt;       case SYMLINK_FILE:&lt;br /&gt;       default: $pswitch = ''; break;&lt;br /&gt;    }&lt;br /&gt;    // Change / to \ because it will break otherwise.&lt;br /&gt;    $target = str_replace('/', '\\', $target);&lt;br /&gt;    $link = str_replace('/', '\\', $link);&lt;br /&gt;    return exec('mklink ' . $pswitch . ' "' . $link . '" "' . $target . '"');&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-8916455302646257439?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8916455302646257439" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8916455302646257439" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/creates-symbolic-link.html" title="Creates A Symbolic Link" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-3703294164196702046</id><published>2007-12-25T14:51:00.000Z</published><updated>2007-12-25T14:52:33.222Z</updated><title type="text">Create A Hard Link</title><content type="html">Make link recursively :&lt;br /&gt;&amp;lt;?php&lt;br /&gt;function makeRecusLink($orig, $dest)&lt;br /&gt;{&lt;br /&gt;    if (is_dir($orig)) {&lt;br /&gt;        if (substr($orig, -1) != '/') {&lt;br /&gt;            $orig .= '/';&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        $handle = opendir($orig);&lt;br /&gt;&lt;br /&gt;        while (false !== ($file = readdir($handle))) {&lt;br /&gt;            if ($file != '.' &amp;&amp; $file != '..') {&lt;br /&gt;                $path = $orig.$file;&lt;br /&gt;&lt;br /&gt;                if (is_file($path)) {&lt;br /&gt;                    @link($path, $dest.'/'.$file);&lt;br /&gt;                } else if (is_dir($path)) {&lt;br /&gt;                    @mkdir($dest.'/'.$file, 0755);                   &lt;br /&gt;                    makeRecusLink($path, $dest.'/'.$file);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    closedir($handle);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;other example&lt;br /&gt;&lt;br /&gt;For a backup utility I needed link-like functionality on a windows system. As it isn't availible on windows, i tried to do it myself with the help of some tools. All you need is junction.exe from sysinternals in your %PATH%.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if(!function_exists('link')){ // Assume a windows system&lt;br /&gt;    function link($target, $link){&lt;br /&gt;        if(is_dir($target)){&lt;br /&gt;            // junctions link to directories in windows&lt;br /&gt;            exec("junction $link $target", $lines, $val);&lt;br /&gt;            return 0 == $val;&lt;br /&gt;        }elseif(is_file($target)){&lt;br /&gt;            // Hardlinks link to files in windows&lt;br /&gt;            exec("fsutil hardlink create $link $target", $lines, $val);&lt;br /&gt;            return 0 == $val;&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;        return false;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-3703294164196702046?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/3703294164196702046" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/3703294164196702046" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/create-hard-link.html" title="Create A Hard Link" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-314245089285128957</id><published>2007-12-23T18:32:00.000Z</published><updated>2007-12-23T18:33:46.808Z</updated><title type="text">Calculates The MD5 Hash Of A Given File</title><content type="html">It's much faster to call an 'exec' command to openssl md5 than to use md5_file.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$file_path = '/path/to/large/video_file.mov';&lt;br /&gt;&lt;br /&gt;$begin = microtime(true);&lt;br /&gt;&lt;br /&gt;$hash = md5_file($file_path);&lt;br /&gt;&lt;br /&gt;$end = microtime(true) - $begin;&lt;br /&gt;&lt;br /&gt;echo "Hash = $hash; time = $end&lt;br&gt;";&lt;br /&gt;# Hash = eac425a6f5b90f69e74710b015228640; time = 2.5333859920502&lt;br /&gt;&lt;br /&gt;$begin = microtime(true);&lt;br /&gt;&lt;br /&gt;$result = split('=',exec("openssl md5 $file_path"));&lt;br /&gt;&lt;br /&gt;$end = microtime(true) - $begin;&lt;br /&gt;&lt;br /&gt;echo "Hash = ".$result[1]."; time = $end";&lt;br /&gt;#Hash = eac425a6f5b90f69e74710b015228640; time = 0.79528999328613&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;I consistently see about a 3x improvement in speed.&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-314245089285128957?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/314245089285128957" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/314245089285128957" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/calculates-md5-hash-of-given-file.html" title="Calculates The MD5 Hash Of A Given File" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-5187146209533323502</id><published>2007-12-23T18:31:00.000Z</published><updated>2007-12-23T18:32:47.702Z</updated><title type="text">Calculate The Md5 Hash Of A String</title><content type="html">Here's a better password checker that tries to guess the password in a certain order.  I found that the random guess ones would never do anything more than 3-4 characters because random guesses are never guaranteed to touch all the guesses.&lt;br /&gt;&lt;br /&gt;This is a sequential password guesser, it needs to know the length of the target password.  Maybe someone can add on variable length passwords.  All you have to do is adjust the fingerprint size and reset it to all zeros.&lt;br /&gt;&lt;br /&gt;it can guess "foo" as the password in 6 seconds on 1.7Ghz athlon (bogomips: 3504)&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt; set_time_limit(0);&lt;br /&gt; $_GET['password'] = $argv[1];&lt;br /&gt; $_GET['length'] = @$argv[2];&lt;br /&gt;&lt;br /&gt; function randomkeys($length)&lt;br /&gt; {&lt;br /&gt;     $pattern =&lt;br /&gt;"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";&lt;br /&gt;     $pattern .= "abcdefghijklmnopqrstuvwxyz";&lt;br /&gt;     $key  = $pattern{rand(0,61)};&lt;br /&gt;     for($i=1;$i&lt;$length;$i++)&lt;br /&gt;     {&lt;br /&gt;         $key .= $pattern{rand(0,61)};&lt;br /&gt;     }&lt;br /&gt;     return $key;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; function getpwguess($length, &amp;$fingerprint) {&lt;br /&gt;     static $allchars = array(&lt;br /&gt;'1','2','3','4','5','6','7','8','9','0',&lt;br /&gt;'a','b','c','d',&lt;br /&gt;'e','f','g','h','i','j',&lt;br /&gt;'k','l','m','n',&lt;br /&gt;'o','p','q','r','s','t','u','v',&lt;br /&gt;'w','x','y','z','A','B','C',&lt;br /&gt;'D','E','F','G','H','I','J','K','L',&lt;br /&gt;'M','N','O','P','Q','R','S','T',&lt;br /&gt;'U','V','W','X','Y','Z');&lt;br /&gt;    $guess = array();&lt;br /&gt;    $next = false;&lt;br /&gt;    foreach ($fingerprint as $index =&gt; $fing) {&lt;br /&gt;&lt;br /&gt;        if ($next == true) {&lt;br /&gt;            $fingerprint[$index]++;&lt;br /&gt;            $fing++;&lt;br /&gt;            $next = false;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        if ($fing == 62) {&lt;br /&gt;            $fingerprint[$index] = 0;&lt;br /&gt;            $fing = 0;&lt;br /&gt;            $next = true;&lt;br /&gt;            $guess[]  = $allchars[$fing];&lt;br /&gt;            continue;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        $guess[]  = $allchars[$fing];&lt;br /&gt;    }&lt;br /&gt;    $fingerprint[0]++;&lt;br /&gt;&lt;br /&gt;    return implode('',$guess);&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; if (isset($_GET['password'])){&lt;br /&gt; $password = $_GET['password'];&lt;br /&gt; $password_length = strlen($password);&lt;br /&gt; }&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt; $password_length = 3;&lt;br /&gt; if (isset($_GET['length'])){&lt;br /&gt; $password_length = $_GET['length'];}&lt;br /&gt; $password = randomkeys($password_length);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; echo "Password is: $password \n";&lt;br /&gt; $password = md5($password);&lt;br /&gt; $attempts = 0;&lt;br /&gt; $start = microtime(true);&lt;br /&gt; $guess = '';&lt;br /&gt; $fingerprint = array();&lt;br /&gt; for ($x=0; $x &lt; $password_length; $x++) {&lt;br /&gt;     $fingerprint[$x] = 0;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; while ($password != $guess){&lt;br /&gt;    $rndm = getpwguess($password_length,$fingerprint);&lt;br /&gt;    $guess = md5($rndm);&lt;br /&gt;    $attempts++;&lt;br /&gt;     //echo "tried $rndm... (skipping 100)\r\n";&lt;br /&gt;    if ($attempts % 1000 ==0 ) {&lt;br /&gt;     echo "tried $rndm... (skipping 1000)\r\n";&lt;br /&gt;    }&lt;br /&gt;    //if the last bucket is 62, then we've tried them all&lt;br /&gt;    if ($fingerprint[ ($password_length-1)] == 62) {&lt;br /&gt;        echo "Tried every combination, maybe password isn't ".$password_length." chars long?\n";&lt;br /&gt;        //here is where you would increase password length, re-init fingerprint array&lt;br /&gt;        //  if you didn't know the target length.&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt; $end = microtime(true);&lt;br /&gt; $time = $end-$start;&lt;br /&gt; echo "Password guessed ('".$rndm."') correctly after $attempts attempts and $time seconds";&lt;br /&gt; ?&amp;gt;&lt;br /&gt;&lt;br /&gt;This code was modified from other people work.  I'm not certain what kind of license it's under, I would vote for BSD.&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-5187146209533323502?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5187146209533323502" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5187146209533323502" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/calculate-md5-hash-of-string.html" title="Calculate The Md5 Hash Of A String" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-8356559672312397976</id><published>2007-12-23T18:29:00.000Z</published><updated>2007-12-23T18:31:22.736Z</updated><title type="text">Alias Of  rtrim Function</title><content type="html">chop() is different than the Perl chop() function, which removes the last character in the string. Another possible one would be to use this:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;function chup(){&lt;br /&gt;$ar=Array();&lt;br /&gt;foreach(func_get_args() as $b) {&lt;br /&gt;push($ar,$b[strlen($b)-1]);&lt;br /&gt;&amp;$b[strlen($b)-1]='';&lt;br /&gt;  }&lt;br /&gt;return $ar;&lt;br /&gt; }&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;If you wanted to perl-chop a va list of strings and return the removed chars. Obviously you can easily mod it for va list arrays of strings and the like.&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-8356559672312397976?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8356559672312397976" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/8356559672312397976" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/alias-of-rtrim-function.html" title="Alias Of  rtrim Function" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-1707713293026989142</id><published>2007-12-23T18:27:00.000Z</published><updated>2007-12-23T18:29:28.868Z</updated><title type="text">Round Fractions Up</title><content type="html">the fCeil and round_up listed below are not reliable.  This could be due to a broken ceil function:&lt;br /&gt;&lt;br /&gt;CODE:&lt;br /&gt;function fCeil($val,$pressision=2){&lt;br /&gt;  $p = pow(10,$pressision);&lt;br /&gt;  $val = $val*$p;&lt;br /&gt;  $val = ceil($val);&lt;br /&gt;  return $val /$p;&lt;br /&gt;}&lt;br /&gt;print "fCeil: ".fCeil("0.5500",2)."\n";&lt;br /&gt;print "ceil:  ".ceil("55.00")."\n";&lt;br /&gt;print "ceil:  ".ceil(0.5500 * 100)."\n"; // should be interpreted as ceil(55);&lt;br /&gt;&lt;br /&gt;OUTPUT:&lt;br /&gt;fCeil: 0.56&lt;br /&gt;ceil:  55&lt;br /&gt;ceil:  56&lt;br /&gt;&lt;br /&gt;Tested: PHP v5.2.2, v5.1.6, v5.0.4 CLI&lt;br /&gt;&lt;br /&gt;Quick function I used as replacement:&lt;br /&gt;&lt;br /&gt;CODE:&lt;br /&gt;function round_up ($value, $precision=2) {&lt;br /&gt;  $amt = explode(".", $value);&lt;br /&gt;  if(strlen($amt[1]) &gt; $precision) {&lt;br /&gt;    $next = (int)substr($amt[1],$precision);&lt;br /&gt;    $amt[1] = (float)(".".substr($amt[1],0,$precision));&lt;br /&gt;    if($next != 0) {&lt;br /&gt;      $rUp = "";&lt;br /&gt;      for($x=1;$x&lt;$precision;$x++) $rUp .= "0";&lt;br /&gt;      $amt[1] = $amt[1] + (float)(".".$rUp."1");&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  else {&lt;br /&gt;    $amt[1] = (float)(".".$amt[1]);&lt;br /&gt;  }&lt;br /&gt;  return $amt[0]+$amt[1];&lt;br /&gt;}&lt;br /&gt;print round_up("0.5500",2)."\n";&lt;br /&gt;print round_up("2.4320",2)."\n";&lt;br /&gt;&lt;br /&gt;print "\nprecision: 2\n";&lt;br /&gt;print round_up("0.5",2)."\n";&lt;br /&gt;print round_up("0.05",2)."\n";&lt;br /&gt;print round_up("0.050",2)."\n";&lt;br /&gt;print round_up("0.0501", 2)."\n";&lt;br /&gt;print round_up("0.0500000000001", 2)."\n";&lt;br /&gt;&lt;br /&gt;print "\nprecision: 3\n";&lt;br /&gt;print round_up("0.5",3)."\n";&lt;br /&gt;print round_up("0.05",3)."\n";&lt;br /&gt;print round_up("0.050",3)."\n";&lt;br /&gt;print round_up("0.0501",3)."\n";&lt;br /&gt;print round_up("0.0500000000001",3)."\n";&lt;br /&gt;&lt;br /&gt;OUTPUT:&lt;br /&gt;0.55&lt;br /&gt;2.44&lt;br /&gt;&lt;br /&gt;precision: 2&lt;br /&gt;0.5&lt;br /&gt;0.05&lt;br /&gt;0.05&lt;br /&gt;0.06&lt;br /&gt;0.06&lt;br /&gt;&lt;br /&gt;precision: 3&lt;br /&gt;0.5&lt;br /&gt;0.05&lt;br /&gt;0.05&lt;br /&gt;0.051&lt;br /&gt;0.051&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-1707713293026989142?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/1707713293026989142" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/1707713293026989142" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/round-fractions-up.html" title="Round Fractions Up" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-4529144925944742230</id><published>2007-12-21T16:34:00.002Z</published><updated>2007-12-21T16:35:24.994Z</updated><title type="text">Find Highest Value</title><content type="html">&amp;lt;?php&lt;br /&gt;echo max(1, 3, 5, 6, 7);  // 7&lt;br /&gt;echo max(array(2, 4, 5)); // 5&lt;br /&gt;&lt;br /&gt;echo max(0, 'hello');     // 0&lt;br /&gt;echo max('hello', 0);     // hello&lt;br /&gt;echo max(-1, 'hello');    // hello&lt;br /&gt;&lt;br /&gt;// With multiple arrays, max compares from left to right&lt;br /&gt;// so in our example: 2 == 2, but 4 &lt; 5&lt;br /&gt;$val = max(array(2, 4, 8), array(2, 5, 7)); // array(2, 5, 7)&lt;br /&gt;&lt;br /&gt;// If both an array and non-array are given, the array&lt;br /&gt;// is always returned as it's seen as the largest&lt;br /&gt;$val = max('string', array(2, 5, 7), 42);   // array(2, 5, 7)&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-4529144925944742230?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4529144925944742230" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4529144925944742230" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/find-highest-value.html" title="Find Highest Value" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-7674988226968119326</id><published>2007-12-21T16:34:00.001Z</published><updated>2007-12-21T16:34:40.763Z</updated><title type="text">Find Lowest Value</title><content type="html">&amp;lt;?php&lt;br /&gt;echo min(2, 3, 1, 6, 7);  // 1&lt;br /&gt;echo min(array(2, 4, 5)); // 2&lt;br /&gt;&lt;br /&gt;echo min(0, 'hello');     // 0&lt;br /&gt;echo min('hello', 0);     // hello&lt;br /&gt;echo min('hello', -1);    // -1&lt;br /&gt;&lt;br /&gt;// With multiple arrays, min compares from left to right&lt;br /&gt;// so in our example: 2 == 2, but 4 &lt; 5&lt;br /&gt;$val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)&lt;br /&gt;&lt;br /&gt;// If both an array and non-array are given, the array&lt;br /&gt;// is never returned as it's considered the largest&lt;br /&gt;$val = min('string', array(2, 5, 7), 42);   // string&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;echo min(2, 3, 1, 6, 7);  // 1&lt;br /&gt;echo min(array(2, 4, 5)); // 2&lt;br /&gt;&lt;br /&gt;echo min(0, 'hello');     // 0&lt;br /&gt;echo min('hello', 0);     // hello&lt;br /&gt;echo min('hello', -1);    // -1&lt;br /&gt;&lt;br /&gt;// With multiple arrays, min compares from left to right&lt;br /&gt;// so in our example: 2 == 2, but 4 &lt; 5&lt;br /&gt;$val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8)&lt;br /&gt;&lt;br /&gt;// If both an array and non-array are given, the array&lt;br /&gt;// is never returned as it's considered the largest&lt;br /&gt;$val = min('string', array(2, 5, 7), 42);   // string&lt;br /&gt;?&gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-7674988226968119326?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/7674988226968119326" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/7674988226968119326" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/find-lowest-value.html" title="Find Lowest Value" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-4998579664847875986</id><published>2007-12-21T16:31:00.000Z</published><updated>2007-12-21T16:33:19.547Z</updated><title type="text">Easier Way to Find Perfect Squares</title><content type="html">A much easier way to find perfect squares:&lt;br /&gt;This method uses integer roots to find perfect squares instead of integer squares to find integer roots.&lt;br /&gt;&lt;br /&gt;&amp;lt;?&lt;br /&gt;&lt;br /&gt;# initial value&lt;br /&gt;$i = 0;&lt;br /&gt;&lt;br /&gt;#set any limit you want&lt;br /&gt;$setSomeLimit = 10000;&lt;br /&gt;&lt;br /&gt;# do it! .... do it! ... do it!&lt;br /&gt;for ($n = 1; $n &lt; sqrt($setSomeLimit; $n++)&lt;br /&gt;{&lt;br /&gt;    // Find the square&lt;br /&gt;    $s= $n * $n;&lt;br /&gt;&lt;br /&gt;    print "&lt;br&gt;perfect_square_root is of $s is $n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-4998579664847875986?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4998579664847875986" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/4998579664847875986" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/easier-way-to-find-perfect-squares.html" title="Easier Way to Find Perfect Squares" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-5929801332002916961</id><published>2007-12-20T16:13:00.000Z</published><updated>2007-12-20T16:14:04.628Z</updated><title type="text">How To Connect To a IRC Server</title><content type="html">This is an example to show how to connect to a IRC server, how to join a channel, send and receive messages.&lt;br /&gt;&lt;br /&gt;&amp;lt;?PHP&lt;br /&gt;&lt;br /&gt;/* change it to your own nickname                                               */&lt;br /&gt;$nickname               = "myOwnNick";&lt;br /&gt;/* choice your irc server                                                       */&lt;br /&gt;$server                 = "irc.brasirc.net";&lt;br /&gt;/* change to your channel                                                       */&lt;br /&gt;$channel                = "#linux";&lt;br /&gt;/* do not change it if you do not know what means :-)                           */&lt;br /&gt;$port                   = "6667";&lt;br /&gt;&lt;br /&gt;/* as ircg cannot resolve hosts, we use PHP internal function to get the IP     */&lt;br /&gt;$ip                     = gethostbyname($server);&lt;br /&gt;&lt;br /&gt;/* connection                                                                   */&lt;br /&gt;$id                     = ircg_pconnect($nickname,$ip,$port);&lt;br /&gt;&lt;br /&gt;/* checking if  connected                                                       */&lt;br /&gt;if (!ircg_is_conn_alive($id))&lt;br /&gt;{&lt;br /&gt;        print "Cannot connect&lt;br&gt;";&lt;br /&gt;        exit;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* joining a channel                                                            */&lt;br /&gt;if (!ircg_join($id,$channel))&lt;br /&gt;{&lt;br /&gt;        print "Cannot join to $chanell&lt;br&gt;";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* getting messages - you must have this in your php file                       */&lt;br /&gt;ircg_set_current($id);&lt;br /&gt;&lt;br /&gt;/* send messages to your channel and you                                        */&lt;br /&gt;ircg_msg($id,$channel,"Hello $channel!!");&lt;br /&gt;ircg_msg($id,$nickname,"This message goes to me!!!");&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-5929801332002916961?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5929801332002916961" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/5929801332002916961" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/how-to-connect-to-irc-server.html" title="How To Connect To a IRC Server" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-2021736313214984556</id><published>2007-12-19T07:04:00.000Z</published><updated>2007-12-19T07:05:50.102Z</updated><title type="text">Gets Options From The Command Line Argument List</title><content type="html">&amp;lt;?php&lt;br /&gt;$shortopts  = "";&lt;br /&gt;$shortopts .= "f:";  // Required value&lt;br /&gt;$shortopts .= "v::"; // Optional value&lt;br /&gt;$shortopts .= "abc"; // These options do not accept values&lt;br /&gt;&lt;br /&gt;$longopts  = array(&lt;br /&gt;    "required:",     // Required value&lt;br /&gt;    "optional::",    // Optional value&lt;br /&gt;    "option",        // No value&lt;br /&gt;    "opt",           // No value&lt;br /&gt;);&lt;br /&gt;$options = getopt($shortopts, $longopts);&lt;br /&gt;var_dump($options);&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-2021736313214984556?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/2021736313214984556" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/2021736313214984556" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/gets-options-from-command-line-argument.html" title="Gets Options From The Command Line Argument List" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry><entry><id>tag:blogger.com,1999:blog-1985129778314828705.post-6582297498488678965</id><published>2007-12-19T07:02:00.000Z</published><updated>2007-12-19T07:03:42.050Z</updated><title type="text">Gets PHP's process ID</title><content type="html">What is the difference between posix_getpid() and getmypid()? It appears that they're implemented differently. I wrote this quick test script:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$max = 1000000;&lt;br /&gt;&lt;br /&gt;$arr = array();&lt;br /&gt;$a_0 = microtime(TRUE);&lt;br /&gt;for ($i=0; $i&lt;$max; $i++) {&lt;br /&gt;        $arr[] = getmypid();&lt;br /&gt;}&lt;br /&gt;$a_1 = microtime(TRUE);&lt;br /&gt;&lt;br /&gt;$arr = array();&lt;br /&gt;$b_0 = microtime(TRUE);&lt;br /&gt;for ($i=0; $i&lt;$max; $i++) {&lt;br /&gt;        $arr[] = posix_getpid();&lt;br /&gt;}&lt;br /&gt;$b_1 = microtime(TRUE);&lt;br /&gt;&lt;br /&gt;$diff_a = $a_1 - $a_0;&lt;br /&gt;$diff_b = $b_1 - $b_0;&lt;br /&gt;echo "A: $diff_a, B: $diff_b: " . ($diff_b / $diff_a) . "\n";&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;I ran this a number of times, and time got results similar to this:&lt;br /&gt;&lt;br /&gt;A: 1.1289880275726, B: 1.1726188659668: 1.0386459708417&lt;br /&gt;&lt;br /&gt;So it's around 4% faster to use getmypid().&lt;div class="blogger-post-footer"&gt;phpeverywhere.blogspot.com&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1985129778314828705-6582297498488678965?l=phpeverywhere.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/6582297498488678965" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/1985129778314828705/posts/default/6582297498488678965" /><link rel="alternate" type="text/html" href="http://phpeverywhere.blogspot.com/2007/12/gets-phps-process-id.html" title="Gets PHP's process ID" /><author><name>Oriol</name><uri>http://www.blogger.com/profile/16164132079854872617</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="09656835336519057199" /></author></entry></feed>
