2015-11-18 174 views
0

我希望能够点击其内具有特定信息的链接 -删除部分

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

ID =系列-99是我想的信息能够作为变量页面上使用 - index.php?content=quiz-demo-1

1页1 - 上mysite.com/Page_1 mysite.com/Page_1

2-链接:点击此处 - <a href="index.php?content=quiz-demo-1id=series-99">

3,新页面的URL - mysite.com/index.php?content=quiz-demo-1

4 - 新的页面代码:

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

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

我想:id=series-99落了新的URL。

谢谢!

+1

http://php.net/manual/en/function.parse-url.php –

回答

0

你可以使用这个正则表达式(我已经纠正您的网址,并添加了一个符号):

$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; 

然而,这将是可能使用更安全的mentionned parse_url(),如果你不熟悉规则表达式。