将javascript放入PHP中
我尝试将document.URL放入PHP代码中,如下命令所示:将javascript放入PHP中,javascript,php,string,Javascript,Php,String,我尝试将document.URL放入PHP代码中,如下命令所示: > $string=explode('/',document.URL) 我肯定这不管用,但是有什么办法可以解决这个问题吗?我是新来的 我们可以做一些事情,比如制作一个从以下位置获取url的函数: …然后我们可以: $string=explode('/',curPageUrl()); 您不能执行JavaScript来返回页面的URL,因为php是在页面加载到服务器上之前运行的,这就是为什么它被称为服务器端语言的原因。即使可
> $string=explode('/',document.URL)
我肯定这不管用,但是有什么办法可以解决这个问题吗?我是新来的 我们可以做一些事情,比如制作一个从以下位置获取url的函数: …然后我们可以:
$string=explode('/',curPageUrl());
您不能执行JavaScript来返回页面的URL,因为php是在页面加载到服务器上之前运行的,这就是为什么它被称为服务器端语言的原因。即使可以,最好使用执行语句所用的语言。Php在服务器上运行。Javascript在浏览器中运行。它们是两个不同的位置。所以你不能把php和javascript混用 你可以试试这个
//Simply call the getCurrentURL() function to get the URL
$string=explode('/', getCurrentURL())
//This function forms the URL you see in your browser
function getCurrentURL()
{
$currentURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$currentURL .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$currentURL .= ":".$_SERVER["SERVER_PORT"];
}
$currentURL .= $_SERVER["REQUEST_URI"];
return $currentURL;
}
Php在服务器上运行。Javascript在浏览器中运行。它们是两个不同的位置。因此,您不能将php与JavaScription混合使用。您最好寻找具有相同功能的php函数。在发布问题之前,试着研究一下,大多数基本的问题都已经在这里得到了回答,你可以在手册中找到的其他问题也会被否定,尽管已经有很多人回答了…为什么人们尝试在javascript中使用php,在php中使用javascript?我从来没有得到过这个。。。
//Simply call the getCurrentURL() function to get the URL
$string=explode('/', getCurrentURL())
//This function forms the URL you see in your browser
function getCurrentURL()
{
$currentURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$currentURL .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$currentURL .= ":".$_SERVER["SERVER_PORT"];
}
$currentURL .= $_SERVER["REQUEST_URI"];
return $currentURL;
}