首页 > 编程知识 正文

url指向php函数,php中url什么意思

时间:2023-12-27 22:26:29 阅读:324372 作者:ZUPV

本文目录一览:

php处理url的几个函数

pathinfo

[php] view plaincopy

?php    

$test = pathinfo("");    

print_r($test);    

?    

结果如下    

Array    

(    

    [dirname] =  //url的路径    

    [basename] = index.php  //完整文件名    

    [extension] = php  //文件名后缀    

    [filename] = index //文件名    

)  

parse_url

[php] view plaincopy

?php    

$test = parse_url(";sex=1#top");    

print_r($test);    

?    

结果如下    

Array    

(    

    [scheme] = http //使用什么协议    

    [host] = localhost //主机名    

    [path] = /index.php //路径    

    [query] = name=tanksex=1 // 所传的参数    

    [fragment] = top //后面根的锚点    

)  

basename

[php] view plaincopy

?php    

$test = basename(";sex=1#top");    

echo $test;    

?    

结果如下    

index.php?name=tanksex=1#top

url直接访问Php中方法

这是不可能的,你应该要把它实例化,

例如

myclass.php

?php

    class test{

        public function abc(){

            echo "this is the function of abc";

        }

    }

    

     //实例化

    $mytest=new test();

    //执行方法

    $mytest-test();

当你浏览器输入这个网站的路径+myclass.php的时候,页面就会显示

this is the function of abc

php如何通过url调用php文件中的方法

题主所描述的这种形式,是MVC设计模式的典型应用。

通过使用PSR4来实现自动加载,可以通过处理路由来实现

//处理路由的方法

static public function route()

{

//获取的模块

$_GET['m'] = isset($_GET['m']) ? $_GET['m'] : 'Index';

//获取行为动作action 又叫方法

$_GET['a'] = isset($_GET['a']) ? $_GET['a'] : 'index';

$controller = 'Controller\' . $_GET['m'] . 'Controller';

//echo $controller;

$c = new $controller();

//$c-$_GET['a']();

call_user_func(array($c , $_GET['a']));

}

最终可实现以下形式:

如何通过PHP获取当前页面URL函数

通过PHP获取当前页面URL函数代码如下,调用时只需要使用 curPageURL() 就可以:

/* 获得当前页面URL开始 */

function curPageURL() {

$pageURL = 'http';

if ($_SERVER["HTTPS"] == "on") {    // 如果是SSL加密则加上“s”

$pageURL .= "s";

}

$pageURL .= "://";

if ($_SERVER["SERVER_PORT"] != "80") {

$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];

} else {

$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

}

return $pageURL;

}

/* 获得当前页面URL结束 */

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。