123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- if (!function_exists('list_to_tree')) {
- function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = 0)
- {
-
- $tree = array();
- if (is_array($list)) {
-
- $refer = array();
- foreach ($list as $key => $data) {
- $refer[$data[$pk]] =& $list[$key];
- }
- foreach ($list as $key => $data) {
-
- $parentId = $data[$pid];
- if ($root == $parentId) {
- $tree[] =& $list[$key];
- } else {
- if (isset($refer[$parentId])) {
- $parent =& $refer[$parentId];
- $parent[$child][] =& $list[$key];
- }
- }
- }
- }
- return $tree;
- }
-
- if (!function_exists('is_mobile')) {
- function is_mobile($val)
- {
- return preg_match('/^1\d{10}$/', $val);
- }
- }
-
- function config_connection($dbConfig)
- {
- config(['database.connections.' . $dbConfig['connection_name'] => [
- 'driver' => 'mysql',
- 'host' => $dbConfig['host'],
- 'port' => $dbConfig['port'],
- 'database' => $dbConfig['database'],
- 'username' => $dbConfig['username'],
- 'password' => $dbConfig['password'],
- 'charset' => 'utf8',
- 'prefix' => 'scn_',
- ]]);
- return $dbConfig['connection_name'];
- }
-
- if (!function_exists('do_log')) {
- function do_log($name = null)
- {
- return new App\Libs\DoLog($name);
- }
- }
-
- function word_count($content)
- {
- $str = strip_tags($content);
- $str = preg_replace('/[\x80-\xff]{1,3}/', ' ', $str, -1, $n);
- $n += str_word_count($str);
- return $n;
- }
-
- function del_domain_from_src($content)
- {
- $url = str_replace('/', '\/', config('app.url'));
- return preg_replace(sprintf('/src="%s/i', $url), 'src="', $content);
- }
- function pre_dump($content)
- {
- echo '<pre>';
- var_dump($content);
- echo '</pre>';
- }
- function encodeStr($string)
- {
- return rtrim(strtr(base64_encode($string), '+/', '-_'), '=');
- }
- function decodeStr($string)
- {
- return base64_decode(strtr($string, '-_', '+/'));
- }
- }
|