如题,返回一个数组,可以获得图片地址的base url,相对地址,名称等,具体见下例:
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
32
33
34
35
36
37
38
39
40
41
|
<? error_reporting (E_ALL ^ E_NOTICE); $imgurl = '//img.jbzj.com/file_images/article/201408/201408232212306.png' ; $imgurl_dir = '/img/2014/07/02/14520384.gif' ; //echo getimg($imgurl,'./img'); var_dump(url_set_value( $imgurl )); var_dump(url_set_value( $imgurl_dir )); /** * function name:url_set_value * User: Don * Date: 14-8-2 * Time: 上午12:43 */ function url_set_value( $url ) { $a = explode ( '/' , $url ); $url_set = array (); for ( $n =0 ; $n < count ( $a ); $n ++) { //var_dump($a); if ( $a [ $n ]== 'http:' ) { $url_set [ 'base_url' ]= $a [ $n +2]; for ( $p = $n +3 ; $p < count ( $a )-1; $p ++) $url_set [ 'img_dir_path' ].= '/' . $a [ $p ]; $url_set [ 'img_path' ]= $a [ count ( $a )-1]; $url_set [ 'img_ful_path' ]= $url_set [ 'img_dir_path' ]. $url_set [ 'img_path' ]; } else { for ( $p =0 ; $p < count ( $a )-1; $p ++) if ( $a [ $p ]!== '' ) $url_set [ 'img_dir_path' ].= '/' . $a [ $p ]; $url_set [ 'img_path' ]= $a [ count ( $a )-1]; $url_set [ 'img_ful_path' ]= $url_set [ 'img_dir_path' ]. $url_set [ 'img_path' ]; } return $url_set ; } } ?> |
运行结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
array (4) { [ "base_url" ]=> string(14) "img.jbzj.com" [ "img_dir_path" ]=> string(27) "/file_images/article/201408" [ "img_path" ]=> string(19) "201408232212306.png" [ "img_ful_path" ]=> string(46) "/file_images/article/201408201408232212306.png" } array (3) { [ "img_dir_path" ]=> string(15) "/img/2014/07/02" [ "img_path" ]=> string(12) "14520384.gif" [ "img_ful_path" ]=> string(27) "/img/2014/07/0214520384.gif" } |