-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode.php
31 lines (28 loc) · 898 Bytes
/
encode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public function encode_curl_url($url)
{
//get scheme url
$scheme =parse_url($url, PHP_URL_SCHEME);
$host = parse_url($url, PHP_URL_HOST);
$port = parse_url($url, PHP_URL_PORT);
$path = parse_url($url, PHP_URL_PATH);
//process path
$explodePath = explode('/', $path);
$endPath = end($explodePath);
$endPath = rawurlencode($endPath); //encode it
// join path
$joinPath = '';
foreach ($explodePath as $p) {
if (!empty($p)) {
if ($p == end($explodePath))
$joinPath .= '/'.$endPath;
else
$joinPath .= '/'.$p;
}
}
$enCodeUrl = $scheme.'://'.$host;
if (isset($port)) {
$enCodeUrl .= ':'.$port;
}
$enCodeUrl .= $joinPath;
return $enCodeUrl;
}