简体   繁体   English

在请求的 URL 中将数字作为参数传递:PHP

[英]Passing numbers as parameters in URL in request: PHP

Can I pass numbers as parameters in URL?我可以在 URL 中将数字作为参数传递吗? I am trying to get the slug name as below,我正在尝试获取如下的 slug 名称,

$slug = $post->post_name;
$pagePath = site_url() . '/listing-details/?p=' . $slug;

and trying to get the slug as below,并尝试如下获得子弹,

$the_slug = $_GET['p'];

Now the issue here, in some cases I am getting the $slug value as something like现在的问题是,在某些情况下,我得到的 $slug 值类似于

650-jefferson-ave 650-jefferson-ave

Thus finally my URL which I am getting, becomes:因此,最终我得到的 URL 变成了:

http://localhost/project/listing-details/?p=650-jefferson-ave http://localhost/project/listing-details/?p=650-jefferson-ave

Thus in that case my $the_$slug is returning null and this url is redirecting the default http://localhost/project/listing-details/ page without any parameters.因此,在这种情况下,我的 $the_$slug 返回 null,并且此 url 重定向默认的 http://localhost/project/listing-details/ 页面,不带任何参数。

How can I achieve this?我怎样才能做到这一点? Please anyone help.请任何人帮助。

$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['email'];

and make sure you have a parameter p after your url并确保您的网址后有一个参数p

like

/post/?p=something

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM