Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PHP
support
Commits
8c556554
Commit
8c556554
authored
5 years ago
by
王海洋
Browse files
Options
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
d933df1c
b82724a7
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+22
-0
README.md
example/url.php
+22
-0
example/url.php
src/Sign.php
+6
-1
src/Sign.php
src/URL.php
+81
-0
src/URL.php
with
131 additions
and
1 deletion
+131
-1
README.md
View file @
8c556554
...
...
@@ -105,3 +105,25 @@ Nested::unlimitedForlayer($cate)
> 返回所有子级分类
## 4.URL操作
## 4.1 URL::parse(String $url)
> 解析URL
## 4.2 URL::params(String $url)
> 解析URL上的参数
## 4.3 URL::build(Array $params,String $uri)
> 数组转为url参数
## 4.4 URL::uri(String $uri)
> 返回url中的url信息
## 4.5 URL::except(String|Array $filter,$url)
> 清楚url参数中的某个值
This diff is collapsed.
Click to expand it.
example/url.php
0 → 100644
View file @
8c556554
<?php
require
__DIR__
.
'/../vendor/autoload.php'
;
use
Yjtec\Support\URL
;
$url
=
"http://dev.mapbd.360vrsh.com/user?ticket=WnTw5qPtlo3PaxQxiwy9a4uvWiDUx1iozd65ts9EXSeBjxt1y2u5ctfKdXHo&type=1&b=2"
;
$urlParams
=
[
'ticket'
=>
'WnTw5qPtlo3PaxQxiwy9a4uvWiDUx1iozd65ts9EXSeBjxt1y2u5ctfKdXHo'
,
'type'
=>
1
];
//print_r(URL::parse($url)); // 解析url
//print_r(URL::params($url));
//echo URL::build($urlParams,'http://dev.mapbd.360vrsh.com/user');
//
//URL::init($url)->except('ticket')->url();
//echo URL::build(['ab'=>1,'c'=>2],'http://www.baidu.com');
//echo URL::uri($url);
echo
URL
::
except
(
'ticket'
,
$url
);
?>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Sign.php
View file @
8c556554
...
...
@@ -8,7 +8,12 @@ class Sign
ksort
(
$params
);
$paramstr
=
''
;
foreach
(
$params
as
$k
=>
$v
)
{
$paramstr
.
=
"
{
$k
}{
$v
}
"
;
if
(
is_array
(
$v
)){
$paramstr
.
=
"
{
$k
}
[]"
.
implode
(
','
,
$v
);
}
else
{
$paramstr
.
=
"
{
$k
}{
$v
}
"
;
}
}
$str
=
"
{
$secret
}
-
{
$paramstr
}
-
{
$timeStamp
}
"
;
...
...
This diff is collapsed.
Click to expand it.
src/URL.php
0 → 100644
View file @
8c556554
<?php
namespace
Yjtec\Support
;
class
URL
{
protected
$urlArr
=
[];
public
static
function
parse
(
$uri
)
{
return
parse_url
(
$uri
);
}
public
static
function
params
(
$url
)
{
$urlArr
=
self
::
parse
(
$url
);
if
(
!
isset
(
$urlArr
[
'query'
])
||
$urlArr
[
'query'
]
==
''
)
{
return
[];
}
$paramsStr
=
$urlArr
[
'query'
];
$paramsArr
=
explode
(
'&'
,
$paramsStr
);
$params
=
[];
foreach
(
$paramsArr
as
$param
)
{
list
(
$key
,
$value
)
=
explode
(
'='
,
$param
);
$params
[
$key
]
=
$value
;
}
return
$params
;
}
public
static
function
build
(
$params
,
$uri
=
null
)
{
$tmp
=
[];
foreach
(
$params
as
$k
=>
$param
)
{
$tmp
[]
=
$k
.
'='
.
$param
;
}
$paramStr
=
implode
(
'&'
,
$tmp
);
if
(
$uri
)
{
$ex
=
count
(
$tmp
)
?
'?'
:
''
;
return
$uri
.
$ex
.
$paramStr
;
}
return
$paramStr
;
}
public
static
function
uri
(
$url
)
{
$arr
=
self
::
parse
(
$url
);
$uri
=
''
;
if
(
isset
(
$arr
[
'scheme'
])){
$uri
.
=
$arr
[
'scheme'
]
.
"://"
;
}
if
(
isset
(
$arr
[
'host'
])){
$uri
.
=
$arr
[
'host'
];
}
if
(
isset
(
$arr
[
'port'
])){
$uri
.
=
':'
.
$arr
[
'port'
];
}
if
(
isset
(
$arr
[
'path'
])){
$uri
.
=
$arr
[
'path'
];
}
return
$uri
;
}
public
static
function
except
(
$filter
=
[],
$url
)
{
$uri
=
self
::
uri
(
$url
);
$params
=
self
::
params
(
$url
);
$keys
=
array_keys
(
$params
);
if
(
is_array
(
$filter
)){
foreach
(
$filter
as
$v
)
{
if
(
in_array
(
$v
,
$keys
))
{
unset
(
$params
[
$v
]);
}
}
}
else
{
if
(
in_array
(
$filter
,
$keys
)){
unset
(
$params
[
$filter
]);
}
}
return
self
::
build
(
$params
,
$uri
);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help