[英]How do I pull information from URL in PHP?
可以说url是http://example.com/product/3
,我只想检索http://example.com/product/
之后的内容。 我发现了这一点,它与域相呼应,但是我如何得到这三个域。 其这种方法可靠吗? 我也在使用codeIgniter。
<?php
function curPageURL() {
$pageURL = 'http';
$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;
}
?>
<?php
echo curPageURL();
?>
使用$this->uri->segment(n)
。 它的文档在这里:
http://codeigniter.com/user_guide/libraries/uri.html
对于您的代码,您将使用:
$curPageURL = $this->url->segment(2)
编辑:修复了代码中的错误。
是的,使用codeigniter API的URI类。
base_url的细分为零,因此,在您的情况下,乘积将为细分1,id为2。
$product_id = $this->uri->segment(2)
正如chetan所说,这在用户指南中有明确记录。
您应该改用parse_url: http : //php.net/manual/es/function.parse-url.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.