【问题标题】:remove part of the new url php from link post从链接帖子中删除部分新 url php
【发布时间】:2015-11-18 19:54:21
【问题描述】:

我希望能够点击其中包含特定信息的链接 -

<a href="index.php?content=quiz-demo-1id=series-99">

id=series-99 是我希望能够在页面上用作变量的信息 - index.php?content=quiz-demo-1

1-page#1 - mysite.com/Page_1

2- mysite.com/Page_1 上的链接:单击此处 - &lt;a href="index.php?content=quiz-demo-1id=series-99"&gt;

3-新页面网址 - mysite.com/index.php?content=quiz-demo-1

4 - 新页面代码:

<?php
$quizname = $_GET['id'];
?> 

  <h2><?php echo $quizname?></h2>

我希望:id=series-99 放弃新网址。

谢谢!

【问题讨论】:

标签: php


【解决方案1】:

您可以对此使用正则表达式(我已更正您的网址并添加了一个&符号):

$link = "<a href='index.php?content=quiz-demo-1&id=series-99'>";
$regex = '/(id=[^&"\']+)/i'; // capture everything except the characters in the brackets
$link = preg_replace($regex, "", $link);
echo $link;

但是,如果您不熟悉正则表达式,使用提到的parse_url() 可能会更安全。

【讨论】:

    猜你喜欢
    • 2018-10-23
    • 2013-09-21
    • 2017-09-28
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    相关资源
    最近更新 更多