try - 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.



Your result can be seen below.

Result of php executing





Full code of try.php

  1. <style>
  2. #link_content{font-weight:normal;margin:0 auto;width:650px;padding:10px;}
  3. #link_content table{border-collapse:collapse;margin:0px auto;}
  4. #link_content table td{ border:1px solid #075295; padding:5px;}
  5. #link_content table td:nth-child(1){width:550px;}
  6. #link_content table td:nth-child(2){width:100px;text-align:center;}
  7. #link_content .phead {padding:10px;font-weight:bold;text-align:center;background:#075295;color:white;}
  8. #link_content .link2{}
  9. #link_content .link2:hover{background:#ebebeb;cursor:pointer;}
  10. #link_content .link2 table{display:none;}
  11. #link_content .link2 div{display:none;}
  12. .highland{background:#ebebeb;font-weight:bold;}
  13. .colorBox div {text-align:center;}
  14. .colorBox hr{margin:5px;}
  15. .colorBox table{margin:10px auto;width:350px;border-collapse:collapse;text-align:center;font-weight:normal;}
  16. .colorBox table thead td{border:1px solid white;padding:30px 0px;font-size:18px;}
  17. .colorBox table tbody th { border:1px solid #075295; padding:10px;}
  18. .colorBox table tbody td { border:1px solid #075295; padding:5px;}
  19. .colorBox table th{background:#075295;color:white;}
  20. </style>
  21. <script>
  22.   $(document).ready(function() {      
  23.          var procedura = $('<h3>Denumire procedura</h3><br/>');
  24.      $('#link_content .link2').click(function(){
  25.         var tbl = $(this).children().find('table');
  26.                 $.colorbox({
  27.                   inline:true,
  28.                   open:true,
  29.                   href:tbl,
  30.                   transition:"none",
  31.                   width:"600px",
  32.                   height:"500px",
  33.                   opacity: 0.5,
  34.                   fixed:true,
  35.                   className:"colorBox"
  36.                 });
  37.         return false;
  38.         });             
  39.   });
  40. </script>
  41.  
  42. <?php
  43.  
  44. $dir='achizitii_publice';
  45.  
  46.  
  47. //Returneaza continutul
  48. $link_content = dirToArray($dir,0,2);
  49. uksort($link_content,'cmp');
  50. $link_content=array2html($link_content);
  51.  
  52.  
  53. function cmp($a, $b){
  54.   $a = date('Y-m-d', strtotime(str_replace('.','-',substr(end(explode('/',$a)),0,10))));
  55.   $b = date('Y-m-d', strtotime(str_replace('.','-',substr(end(explode('/',$b)),0,10))));
  56.   if ($a == $b) return 0;
  57.   return ($a > $b) ? -1 : 1;
  58. }
  59.  
  60. function dirToArray($dir,$pass,$stop){
  61.     ++$pass;
  62.     $contents = array();
  63.     foreach (scandir($dir) as $node){
  64.         if ($node == '.' || $node == '..') continue;
  65.                 if ($stop<$pass) continue;
  66.         if (is_dir($dir . '/' . $node)){
  67.             $contents[$dir.'/'.$node] = dirToArray($dir . '/' . $node,$pass,$stop);
  68.         }else{
  69.             $contents[] = $dir.'/'.$node;
  70.         }
  71.     }
  72.     return $contents;
  73. }
  74.  
  75. function array2ul($array){
  76.     $out="<ul>";
  77.     foreach($array as $key => $elem){
  78.         if(!is_array($elem)){
  79.                   $info=pathinfo($elem);
  80.                   $name=basename($elem,'.'.$info['extension']); 
  81.           $out=$out."<li><a href='$elem' target='_blank'>$name</a></li>";     
  82.         }else{
  83.                   $key_name=end(explode('/',$key));
  84.                   
  85.                   if(count(current($array))>0){
  86.                     $out=$out."<li class='m' title='$key_name'>$key_name".array2ul($elem)."</li>"; 
  87.                   }else{
  88.                         $out=$out."<li class='link' title='$key'>$key_name".array2ul($elem)."</li>";
  89.                   }  
  90.                 }  
  91.     }
  92.     $out=$out."</ul>";
  93.     return $out;
  94. }
  95.  
  96. function array2html($array){
  97.             $out="<table>";
  98.                 $i = 0;
  99.     foreach($array as $key => $elem){
  100.         if(!is_array($elem)){
  101.           $title=substr(explode('/',$elem)[1],13);              
  102.                   $info=pathinfo($elem);
  103.                   $dend=basename($elem,'.'.$info['extension']);
  104.                   $href='http://www.metrologieploiesti.ro/'.$elem;
  105.                   if ($i==0){
  106.                   $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>";
  107.                   }else{
  108.                   $out=$out."<tr class='detalii'><td><a href='$href' target='_blank'>$dend</a></td></tr>";
  109.                   }
  110.                   $i++;
  111.         }else{
  112.                   $key_name=explode('/',$key);
  113.                   $key_name2=end($key_name);
  114.                   $datap=explode('-',$key_name2)[0];
  115.                   $denp=substr($key_name2,13);
  116.                   $out=$out."<tr class='link2' title='$denp'><td>$denp".array2html($elem)."</td><td>$datap</td></tr>";
  117.                 }  
  118.     }
  119.     $out=$out."</table>";
  120.     return $out;
  121. }
  122.  
  123.  
  124. ?>
  125.  
  126. <div id="link_content">
  127.  
  128.   <table class="phead"><tr><td>Denumire achizitie</td><td>Data</td></tr></table>
  129.   <?php echo $link_content; ?>
  130. </div>
  131.  
File Description
  • try
  • PHP Code
  • 23 May-2023
  • 4.1 Kb
You can Share it: