很多站长朋友们都不太清楚phpurl类,今天小编就来给大家整理phpurl类,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php 如何通过url参数来访问类,类似于struts2的action调用。 2、 php打开URL的几种方法 3、 php怎么通过一个Url获得文件类型 php 如何通过url参数来访问类,类似于struts2的action调用。用这种方式,最好的办法是写一个统一的入口文件来处理请求参数
// 常量-- 你的网站action路径
AC_ROOT = ''
// 处理类
$action = $_REQUEST['action'] ? $_REQUEST['action'] : 'indexAction';
// 处理方法
$method =$_REQUEST['method'] ? $_REQUEST['method']: 'index';
// 查看类是否存在
$actoinfile = AC_ROOT . $action . '.php';
if(file_exists($actoinfile))
{
// 如果存在
require_once($actoinfile);
// 获取此类的对象
$obj = new $action ();
// 查看处理函数是否存在
if (!method_exists($obj , $method)) {
// 方法不存在返回错误
}
// 进入处理流程
$obj->{$method}();
} else {
// 类不存在 返回错误
}
建议: 你可以看看 Thinkphp 等框架 的入口处理方法, 对你应该很有帮助.
php打开URL的几种方法PHP中打开URL地址的几种方法总结,这里的函数主要用于小偷采集等函数。
1: 用file_get_contents
以get方式获取内容
复制代码 代码如下:
<?php
$url='';
$html = file_get_contents($url);
//print_r($http_response_header);
ec($html);
printhr();
printarr($http_response_header);
printhr();
?>
示例代码2: 用fopen打开url,
以get方式获取内容
复制代码 代码如下:
<?
$fp = fopen($url, 'r');
printarr(stream_get_meta_data($fp));
printhr();
while(!feof($fp)) {
$result .= fgets($fp, 1024);
}
echo "url body: $result";
printhr();
fclose($fp);
?>
示例代码3:用file_get_contents函数,以post方式获取url
复制代码 代码如下:
<?php
$data = array ('foo' =>
'bar');
$data = http_build_query($data);
$opts = array (
'http'
=> array (
'method' => 'POST',
'header'=> "Content-type:
application/x-www-form-urlencoded" .
"Content-Length: " . strlen($data) .
"",
'content' => $data
),
);
$context =
stream_context_create($opts);
$html =
file_get_contents('', false, $context);
echo $html;
?>
示例代码4:用fsockopen函数打开url,以get方式获取完整的数据,包括header和body
复制代码 代码如下:
<?
function get_url
($url,$cookie=false) {
$url = parse_url($url);
$query =
$url[path]."?".$url[query];
ec("Query:".$query);
$fp = fsockopen(
$url[host], $url[port]?$url[port]:80 , $errno, $errstr, 30);
if (!$fp) {
return false;
} else {
$request = "GET $query HTTP/1.1";
$request .= "Host: $url[host]";
$request .= "Connection: Close";
if($cookie) $request.="Cookie: $cookie\n";
$request.="";
fwrite($fp,$request);
while(!@feof($fp)) {
$result .= @fgets($fp,
1024);
}
fclose($fp);
return $result;
}
}
//获取url的html部分,去掉header
function GetUrlHTML($url,$cookie=false) {
$rowdata = get_url($url,$cookie);
if($rowdata)
{
$body=
stristr($rowdata,"");
$body=substr($body,4,strlen($body));
return $body;
}
return false;
}
?>
php怎么通过一个Url获得文件类型概括起来两个方法吧。方法一$string = 'fdjborsnabcdtghrjosthabcrgrjtabc';$string = preg_replace('/[abc]+/i','',$string);方法二把字符串转化成数组$arr = str_split($string);foreach( $arr as $key => $value ){ if( in_array($value,array('a','b','c')) ){ unset($arr[$key]); }}$string = implode('',$arr);强烈推荐方法一,方法二不支持字符串中有中文。
楼主看懂了没有,建议你去后盾人那自学,最近他们在搞实训班培训的活动
关于phpurl类的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于phpurl类 phpurl解码的详细内容...