您好,欢迎访问一九零五行业门户网

PHP如何通过URL访问,获得新的URL 【调用百度地图】

我是想在手机微信上进行一段导航
当前导航的url地址如果录入到ie地址栏中是能正常访问的:http://api.map.baidu.com/direction?origin=latlng:24.481428,118.124813|name:测试起点&destination=latlng:24.503361,118.139877|name:测试终点&mode=driving®ion=厦门&output=html
录入后,回车会发现地址变成了:
http://map.baidu.com/?l=&s=nav%26sn%3d1%24%24%24%2413149737.11%2c2794316.21%24%24%e6%b5%8b%e8%af%95%e8%b5%b7%e7%82%b9%24%24%24%24%24%24%26en%3d1%24%24%24%2413151414.05%2c2796984.18%24%24%e6%b5%8b%e8%af%95%e7%bb%88%e7%82%b9%24%24%24%24%24%24%26sc%3d194%26ec%3d194
想知道如果用php如何实现 根据原来的url,请求后得到新的url?谢谢。
回复讨论(解决方案) 转码的原因是 上面带中文的,我发现微信里,iphone导航页面打不开,是空白的。
但是如果通过url请求后,得到的新url,配置在微信里是可以正常打开百度地图的。
所以我想写一个函数来处理这个,求教高手,谢谢。
原?的url是http://api.map.baidu.com/direction?origin=latlng:24.481428,118.124813|name:测试起点&destination=latlng:24.503361,118.139877|name:测试终点&mode=driving®ion=厦门&output=html
新的url是http://map.baidu.com/?l=&s=nav%26sn%3d1%24%24%24%2413149737.11%2c2794316.21%24%24%e6%b5%8b%e8%af%95%e8%b5%b7%e7%82%b9%24%24%24%24%24%24%26en%3d1%24%24%24%2413151414.05%2c2796984.18%24%24%e6%b5%8b%e8%af%95%e7%bb%88%e7%82%b9%24%24%24%24%24%24%26sc%3d194%26ec%3d194
用新的url就可以打?了,?的不行,?
所以你想可以根url?取新url然後使用?
原?的url是http://api.map.baidu.com/direction?origin=latlng:24.481428,118.124813|name:测试起点&destination=latlng:24.503361,118.139877|name:测试终点&mode=driving®ion=厦门&output=html
新的url是http://map.baidu.com/?l=&s=nav%26sn%3d1%24%24%24%2413149737.11%2c2794316.21%24%24%e6%b5%8b%e8%af%95%e8%b5%b7%e7%82%b9%24%24%24%24%24%24%26en%3d1%24%24%24%2413151414.05%2c2796984.18%24%24%e6%b5%8b%e8%af%95%e7%bb%88%e7%82%b9%24%24%24%24%24%24%26sc%3d194%26ec%3d194
用新的url就可以打?了,?的不行,?
所以你想可以根url?取新url然後使用?
兄弟,是这个意思。我就像 用旧的url产生新的url。
多谢啊。



兄弟,感谢回复。
不过我用的是新浪sae,里面提示我:
warning: get_headers() has been disabled for security reasons in test.php on line 7
get_headers() 还能有别的办法替换么?谢谢。
试试.
$url = 'http://api.map.baidu.com/direction?origin=latlng:24.481428,118.124813|name:测试起点&destination=latlng:24.503361,118.139877|name:测试终点&mode=driving®ion=厦门&output=html';$newurl = getmapurl($url);echo $newurl;function getmapurl($url){ file_get_contents($url); $result = $http_response_header; if($result){ foreach($result as $val){ if(substr($val,0,10)=='location: '){ return str_replace('location: ','', $val); } } } return '';}

禁用的函数:
php_real_logo_guid
php_egg_logo_guid
readlink
linkinfo
symlink
link
set_file_buffer
exec
system
escapeshellcmd
escapeshellarg
passthru
shell_exec
proc_open
proc_close
proc_terminate
proc_get_status
proc_nice
getmyuid
getmygid
getmyinode
putenv
getopt
sys_getloadavg
getrusage
get_current_user
magic_quotes_runtime
set_magic_quotes_runtime
import_request_variables
debug_zval_dump
ini_alter
dl
pclose
popen
stream_socket_client
stream_socket_server
stream_socket_accept
stream_socket_pair
stream_get_transports
stream_wrapper_restore
get_headers
mail
mb_send_mail
openlog
syslog
closelog
apc_add
apc_bin_dump
apc_bin_dumpfile
apc_bin_load
apc_bin_loadfile
apc_cache_info
apc_cas
apc_clear_cache
apc_compile_file
apc_dec
apc_define_constants
apc_delete_file
apc_delete
apc_exists
apc_fetch
apc_inc
apc_load_constants
apc_sma_info
apc_store
flock
pfsockopen
posix_kill
apache_child_terminate
apache_get_modules
apache_get_version
apache_getenv
apache_lookup_uri
apache_reset_timeout
apache_response_headers
apache_setenv
virtual
mysql_pconnect
socket_create
socket_create_pair
禁用的类:
sqlitedatabase
sqliteresult
sqliteunbuffered
sqliteexception
apciterator
urlencode?
试试.
$url = 'http://api.map.baidu.com/direction?origin=latlng:24.481428,118.124813|name:测试起点&destination=latlng:24.503361,118.139877|name:测试终点&mode=driving®ion=厦门&output=html';$newurl = getmapurl($url);echo $newurl;function getmapurl($url){ file_get_contents($url); $result = $http_response_header; if($result){ foreach($result as $val){ if(substr($val,0,10)=='location: '){ return str_replace('location: ','', $val); } } } return '';}

禁用的函数:
php_real_logo_guid
php_egg_logo_guid
readlink
linkinfo
symlink
link
set_file_buffer
exec
system
escapeshellcmd
escapeshellarg
passthru
shell_exec
proc_open
proc_close
proc_terminate
proc_get_status
proc_nice
getmyuid
getmygid
getmyinode
putenv
getopt
sys_getloadavg
getrusage
get_current_user
magic_quotes_runtime
set_magic_quotes_runtime
import_request_variables
debug_zval_dump
ini_alter
dl
pclose
popen
stream_socket_client
stream_socket_server
stream_socket_accept
stream_socket_pair
stream_get_transports
stream_wrapper_restore
get_headers
mail
mb_send_mail
openlog
syslog
closelog
apc_add
apc_bin_dump
apc_bin_dumpfile
apc_bin_load
apc_bin_loadfile
apc_cache_info
apc_cas
apc_clear_cache
apc_compile_file
apc_dec
apc_define_constants
apc_delete_file
apc_delete
apc_exists
apc_fetch
apc_inc
apc_load_constants
apc_sma_info
apc_store
flock
pfsockopen
posix_kill
apache_child_terminate
apache_get_modules
apache_get_version
apache_getenv
apache_lookup_uri
apache_reset_timeout
apache_response_headers
apache_setenv
virtual
mysql_pconnect
socket_create
socket_create_pair
禁用的类:
sqlitedatabase
sqliteresult
sqliteunbuffered
sqliteexception
apciterator
兄弟,给力啊。100分都给你了。结贴,哈。
谢谢。
看的晚了,还找了一个,顺便分享。 private function getheadersnew($url){ $ch= curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_nobody, 1); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 1); $f=curl_exec($ch); curl_close($ch); $h=explode(\n,$f); $r=array(); foreach( $h as $t){ $rr=explode(:,$t,2); if(count($rr)==2 ){ $r[$rr[0]]=trim($rr[1]);} } return $r; }
其它类似信息

推荐信息