JSON

ÈçºÎÔÚphpÖÐÕýÈ·µÄʹÓÃjson(3)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-02-15 16:03 ÎÒÒªÆÀÂÛ( )

×î½üÓÃphp½øÐÐÎļþĿ¼ÐÅÏ¢¶ÁÈ¡£¬ÔÚÍøÉÏŪµ½ÏÂÃæÒ»¶Î´úÂ룺 //»ñÈ¡Ö¸¶¨Ä¿Â¼ÏµÄÎļþÁбí //$path Ö¸¶¨µÄĿ¼£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼ //$ifchild ÊÇ·ñÏÔʾ×ÓĿ¼ÎļþÁÐ±í£¬Ä¬Èϲ»ÏÔʾ //$curpath ÏÔʾµ±Ç°µÄ·¾¶£¬Ä¬ÈÏΪ´Ó

×î½üÓÃphp½øÐÐÎļþĿ¼ÐÅÏ¢¶ÁÈ¡£¬ÔÚÍøÉÏŪµ½ÏÂÃæÒ»¶Î´úÂ룺
//»ñÈ¡Ö¸¶¨Ä¿Â¼ÏµÄÎļþÁбí
//$path Ö¸¶¨µÄĿ¼£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
//$ifchild ÊÇ·ñÏÔʾ×ÓĿ¼ÎļþÁÐ±í£¬Ä¬Èϲ»ÏÔʾ
//$curpath ÏÔʾµ±Ç°µÄ·¾¶£¬Ä¬ÈÏΪ´Óµ±Ç°Ä¿Â¼¿ªÊ¼£»Õâ¸öÖ÷ÒªÊÇΪÁËÏÔʾȷ¶¨href·¾¶

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


function openpath($path=".",$ifchild=false,$curpath=".")
{

$handle = opendir($path);
if($handle)
{
while(false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fullPath = $path.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullPath))//Èç¹ûÊÇĿ¼Îļþ
{
if($ifchild)//Èç¹ûÉèÖÃÁËÏÔʾ×ÓĿ¼
{
//µÝ¹é
openpath($path.DIRECTORY_SEPARATOR.$file,$ifchild,$curpath.DIRECTORY_SEPARATOR.$file);
}
else
{
echo "<li><a href=\"$curpath/$file \" target=\"_blank\">$file</a></li>\n";
}
}
else if($file != basename(__FILE__))//Åųýµ±Ç°Ö´Ðнű¾
{
echo "<li><a href=\"$curpath/$file \" target=\"_blank\">$file</a></li>\n";
}
else
{
echo $file;
}
}
}
}
closedir($handle);
}


ÒòΪ×Ô¼ºÒªÌṩ·¾¶Ñ¡ÔñµÄ¹¦ÄÜ£¬×îºÃÊÇÓÐÒ»¸öÏÂÀ­²Ëµ¥£¬ÀïÃæÓдýѡ·¾¶µÄÏÔʾ£¬ÕâÑù·½±ãºÜ¶à£¬ÓÚÊÇ×Ô¼º¸ÄÁ˸ģ¬°Ñ·¾¶Êä³ö³ÉÒ»¸öÎÞÐòÁÐ±í¡£
ÏÂÃæÊÇÒ»¸öÈ¡µÃµ±Ç°ÎļþÏÂËùÓÐ×ÓÎļþ·¾¶µÄ´úÂ룺

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


/*»ñÈ¡Ö¸¶¨Ä¿Â¼Îļþ·¾¶Áбí
*$path Ö¸¶¨µÄĿ¼£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
*$ifchild ÊÇ·ñ»ñÈ¡×ÓĿ¼ÎļþÁÐ±í£¬Ä¬Èϲ»»ñÈ¡
*$curpath ÏÔʾµ±Ç°µÄ·¾¶£¬Ä¬ÈÏΪ´Óµ±Ç°Ä¿Â¼¿ªÊ¼
*&$pach_html_srt ´«µÝÒ»¸öÍⲿ±äÁ¿µÄÒýÓýøÀ´£¬ÒòΪ´Ë·½·¨ÓпÉÄܱ»µÝ¹éµ÷Óã¬ËùÒÔÒÔÕâÑùµÄ·½Ê½À´±£´æ
* һЩÐÅÏ¢£¬Ò²¿ÉÒÔÓÃÈ«¾Ö±äÁ¿À´ÊµÏÖ£¬ÔÚº¯ÊýÄÚ²¿±äÁ¿¸Ä±äÒ²Ó°Ïìµ½Íⲿ¡£
*&$path_ref_count Ô­ÀíͬÉÏ£¬Ò»¸ö¼ÆÊý±êÖ¾£¬Èç¹ûµÝ¹é£¬¼ÆÊýÆ÷´ÓÉÏÒ»´Î±£´æµÄÖµ¿ªÊ¼×ÔÔö
*/
function openpath($path=".",$ifchild=false,&$path_html_str,&$path_ref_count)
{
$handle = opendir($path);
if($handle)
{
while(false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fullPath = $path.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullPath))//Èç¹ûÎļþÊÇĿ¼
{
$path_html_str.='<li>';
$path_html_str.=$file.'<ul>';
if($ifchild)
{
//µÝ¹é
openpath($path.DIRECTORY_SEPARATOR.$file,$ifchild,&$path_html_str,&$path_ref_count);
}
$path_html_str.='</ul></li>';
}
}
}
}
closedir($handle);
}


ÓÐÁËÉÏÃæµÄ·½·¨£¬ÎҾͿÉÒÔÔÚǰ̨ÓÃjquery mcDropdown²å¼þÀ´ÈÃÓû§¿ÉÒÔͨ¹ýÏÂÀ­²Ëµ¥Ñ¡ÔñÏë½øÈëµÄĿ¼£¬ËùÒÔÐèÒª·â×°³ÉÖ¸¶¨¸ñʽ£º

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


$path_ref_count = 1;
$path_html_str ='';
openpath(".",true,&$path_html_str,&$path_ref_count);
$path_html_str = '<ul>'.$path_html_str.'</ul>';
$path_html_str = str_replace ( "<ul></ul>", '', $path_html_str );


ÕâÑùÎÒ°Ñ$path_html_str´«µ½Ç°Ì¨£¬ÏÔʾ³öÀ´µÄ¾ÍÊÇÒ»¸ö·ûºÏmcDropdownÒªÇóµÄÎÞÐòÁÐ±í£¬¾Í¿ÉÒÔÏÔʾÏàÓ¦µÄ´ýÑ¡ÁбíÁË¡£
ÍêÕû´úÂëÈçÏ£º
test.html

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>test</title>
<script type="text/javascript" src="./lib/jquery.js?1.1.5"></script>
<script type="text/javascript" src="./lib/jquery.mcdropdown.js?1.1.5"></script>
<script type="text/javascript" src="./lib/jquery.bgiframe.js?1.1.5"></script>

<!---// load the mcDropdown CSS stylesheet //--->
<link type="text/css" href="./css/jquery.mcdropdown.css?1.1.5" media="all" />
<script type="text/javascript">
$(document).ready(function (){
var delim = "#delim#";
dd= $("#category").mcDropdown("#categorymenu",{
allowParentSelect:true,
delim:delim
});
});
</script>
</head>
<body>
<p>
Please select a category:<br />
<input type="text" value="" />
</p>
#categorymenu#
</body>
</html>


test.php

¸´ÖÆ´úÂë ´úÂëÈçÏÂ:


<?php
//Ŀ¼ÐÅÏ¢´¦Àí
$path_ref_count = 1;
$path_html_str ='';
openpath(".",true,&$path_html_str,&$path_ref_count);
$path_html_str = '<ul>'.$path_html_str.'</ul>';
$path_html_str = str_replace ( "<ul></ul>", '', $path_html_str );
//var_dump($path_info);
//var_dump($path_html_str);
$str_buffer = file_get_contents (dirname(__FILE__).DIRECTORY_SEPARATOR.'test.html');
$str_buffer = str_replace ( "#categorymenu#", $path_html_str, $str_buffer );
$str_buffer = str_replace ( "#delim#", DIRECTORY_SEPARATOR, $str_buffer );
echo $str_buffer;
/*»ñÈ¡Ö¸¶¨Ä¿Â¼Îļþ·¾¶Áбí
*$path Ö¸¶¨µÄĿ¼£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
*$ifchild ÊÇ·ñ»ñÈ¡×ÓĿ¼ÎļþÁÐ±í£¬Ä¬Èϲ»»ñÈ¡
*$curpath ÏÔʾµ±Ç°µÄ·¾¶£¬Ä¬ÈÏΪ´Óµ±Ç°Ä¿Â¼¿ªÊ¼
*&$pach_html_srt ´«µÝÒ»¸öÍⲿ±äÁ¿µÄÒýÓýøÀ´£¬ÒòΪ´Ë·½·¨ÓпÉÄܱ»µÝ¹éµ÷Óã¬ËùÒÔÒÔÕâÑùµÄ·½Ê½À´±£´æ
* һЩÐÅÏ¢£¬Ò²¿ÉÒÔÓÃÈ«¾Ö±äÁ¿À´ÊµÏÖ£¬ÔÚº¯ÊýÄÚ²¿±äÁ¿¸Ä±äÒ²Ó°Ïìµ½Íⲿ¡£
*&$path_ref_count Ô­ÀíͬÉÏ£¬Ò»¸ö¼ÆÊý±êÖ¾£¬Èç¹ûµÝ¹é£¬¼ÆÊýÆ÷´ÓÉÏÒ»´Î±£´æµÄÖµ¿ªÊ¼×ÔÔö
*/
function openpath($path=".",$ifchild=false,&$path_html_str,&$path_ref_count)
{
$handle = opendir($path);
if($handle)
{
while(false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fullPath = $path.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullPath))//Èç¹ûÎļþÊÇĿ¼
{
$path_html_str.='<li>';
$path_html_str.=$file.'<ul>';
if($ifchild)
{
//µÝ¹é
openpath($path.DIRECTORY_SEPARATOR.$file,$ifchild,&$path_html_str,&$path_ref_count);
}
$path_html_str.='</ul></li>';
}
}
}
}
closedir($handle);
}
?>


jquery mcDropdown ²å¼þ¿ÉÒÔÔÚÕâÀïÏÂÔØ£º

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ¡¾±Ê¼Ç¡¿½ÌÄã¿ìËٸ㶨QtϵÄJsonÎļþʹÓÃ

    ¡¾±Ê¼Ç¡¿½ÌÄã¿ìËٸ㶨QtϵÄJsonÎļþʹÓÃ

    2017-02-08 18:00

  • JavaScriptÐÂÊֽ̳ÌÖ®JSONµÄʹÓÃÈ«½â(³¬Ïêϸ)

    JavaScriptÐÂÊֽ̳ÌÖ®JSONµÄʹÓÃÈ«½â(³¬Ïêϸ)

    2017-02-03 13:00

  • json¸ñʽ½âÎöºÍlibjsonµÄÓ÷¨½éÉÜ(¹ØÓÚcjsonµÄʹÓ÷½·¨)

    json¸ñʽ½âÎöºÍlibjsonµÄÓ÷¨½éÉÜ(¹ØÓÚcjsonµÄʹÓ÷½·¨)

    2017-02-02 13:04

  • ʹÓÃPHP´ÓMySQL´´½¨JSON²¢ÓÃJQuery½âÎö

    ʹÓÃPHP´ÓMySQL´´½¨JSON²¢ÓÃJQuery½âÎö

    2017-02-02 08:00

ÍøÓѵãÆÀ
Ó