<?php
function scanMain($path){
	$dirs = scandir($path);
	$data =[];
	foreach($dirs as $dir){
		if($dir!='.' && $dir!='..'){
			$dir = $path.'/'.$dir;
			if(is_dir($dir)){
				$data[] = $dir;
			}
		}
	}
	return $data;
}

function scanSub($path){
	$dirs = scandir($path);
	$data =[];
	foreach($dirs as $file){
		if($file!='.' && $file!='..'){
			$file = $path.'/'.$file;
			if(is_file($file)){
				$data[] = $file;
			}
		}
	}
	return $data;
}

function getJson(&$arr){
	foreach($arr as $k=>$v){
		if(is_array($v) && !isset($v['example']))
			getJson($arr[$k]);
		else
			$arr[$k] = $v['example'];
	}
}

function getDoc($file){
	$doc = include($file);
	return $doc;
}

function replacechar($str){
	//$str = str_replace("'","\'",$str);
	//$str = str_replace('"','\"',$str);
	return htmlspecialchars($str);
}

function format($str){
	preg_match_all("/(\[([^\]]+)?\])/s",$str,$m);
	$result = $str;
	foreach($m[2] as $v){
		$tmp = explode('.',$v);
		$a = sprintf('<a href="?dir=%s&file=%s">[%s]</a>',$tmp[0],$tmp[1],$v);
		$result = str_replace('['.$v.']',$a,$result);
	}
	return $result;
}
