try2 - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of try2.php
- <?php
- $dir='achizitii_publice';
- //Returneaza continutul
- $link_content = dirToArray($dir,0,2);
- uksort($link_content,'cmp');
- $link_content=array2html($link_content);
- function cmp($a, $b){
- $a = date('Y-m-d', strtotime(str_replace('.','-',substr(end(explode('/',$a)),0,10))));
- $b = date('Y-m-d', strtotime(str_replace('.','-',substr(end(explode('/',$b)),0,10))));
- if ($a == $b) return 0;
- return ($a > $b) ? -1 : 1;
- }
- function dirToArray($dir,$pass,$stop){
- ++$pass;
- $contents = array();
- foreach (scandir($dir) as $node){
- if ($node == '.' || $node == '..') continue;
- if ($stop<$pass) continue;
- if (is_dir($dir . '/' . $node)){
- $contents[$dir.'/'.$node] = dirToArray($dir . '/' . $node,$pass,$stop);
- }else{
- $contents[] = $dir.'/'.$node;
- }
- }
- return $contents;
- }
- function array2ul($array){
- $out="<ul>";
- foreach($array as $key => $elem){
- if(!is_array($elem)){
- $info=pathinfo($elem);
- $name=basename($elem,'.'.$info['extension']);
- $out=$out."<li><a href='$elem' target='_blank'>$name</a></li>";
- }else{
- $key_name=end(explode('/',$key));
- if(count(current($array))>0){
- $out=$out."<li class='m' title='$key_name'>$key_name".array2ul($elem)."</li>";
- }else{
- $out=$out."<li class='link' title='$key'>$key_name".array2ul($elem)."</li>";
- }
- }
- }
- $out=$out."</ul>";
- return $out;
- }
- function array2html($array){
- $out="<table>";
- $i = 0;
- foreach($array as $key => $elem){
- if(!is_array($elem)){
- $title=substr(explode('/',$elem)[1],13);
- $info=pathinfo($elem);
- $dend=basename($elem,'.'.$info['extension']);
- $href='http://www.metrologieploiesti.ro/'.$elem;
- if ($i==0){
- $out=$out."<thead><tr><td>$title<hr></td></tr></thead><tr><th>Documente si clarificari</th></tr><tr class='detalii'><td><a href='$href' target='_blank'>$dend</a></td></tr>";
- }else{
- $out=$out."<tr class='detalii'><td><a href='$href' target='_blank'>$dend</a></td></tr>";
- }
- $i++;
- }else{
- $key_name=explode('/',$key);
- $key_name2=end($key_name);
- $datap=explode('-',$key_name2)[0];
- $denp=substr($key_name2,13);
- $out=$out."<tr class='link2' title='$denp'><td>$denp".array2html($elem)."</td><td>$datap</td></tr>";
- }
- }
- $out=$out."</table>";
- return $out;
- }
- ?>