【问题标题】:how to explode a url string?如何爆炸一个url字符串?
【发布时间】:2017-04-20 05:28:53
【问题描述】:

代码:

<?php
    include('conn.php');
    $student_id = $_SESSION['student_id'];
    $college_name = $_GET['college_name'];
    $college_name22 = explode('(', $college_name);
    if(preg_match('#\((.*?)\)#', $college_name, $match))
    {
        $match[1] = lcfirst($match[1]);
    }
    else
    {
        $match[1] = 'All';
    }

?>

如果 url 有类似

的字符串
cstest/view.php?college_name=Agra%20Public%20Institute%20of%20Technology%20&%20Computer%20Education,%20Artoni%20(Pharmacy)

我想分解以下字符串,即

Agra%20Public%20Institute%20of%20Technology%20&%20Computer%20Education,%20Artoni%20(Pharmacy)

当我回显 $college_name 时,它​​只显示 (Agra Public Institute of Technology) 而不是全名,即 (Agra Public Institute of Technology & Computer Education, Artoni) 和 $match[1] 包含 (pharmacy),当我没有显示打印 $match[1] 它显示“全部”。那么,我该如何解决这个问题呢?

谢谢

【问题讨论】:

  • var_dump($_GET) 看起来像什么?对于初学者,它不会包含 URL 编码的字符串。如果您访问的 URL 中包含 ,(,则您的浏览器有问题,它们也会被编码为 %2C 和 %28。

标签: php


【解决方案1】:

&amp; 在 URL 中具有特殊含义。 $_GET['college_name'] 的值正好是“Agra%20Public%20Institute%20of%20Technology%20”。 &amp; 标志着新参数的开始。

如果 & 符号被正确地转义为 %26,您将会轻松很多。

您可以尝试插入 var_dump($_GET) 并查看您实际使用的数据是什么。

【讨论】:

  • 我正在使用 var_dump,例如 $college_name = var_dump($_GET['college_name']);并给出以下结果,如 string(36) "Agra Public Institute of Technology
  • var_dump 整个数组,$_GET。看看你还有什么。
猜你喜欢
  • 2011-09-04
  • 1970-01-01
  • 1970-01-01
  • 2020-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多