找到页面网址

时间:2014-11-03 13:19:02

标签: php

我有页面,但我没有显示特定网址的特定区块。 所以我的网址是 www.example.com/products/product1.html www.example.com/products/product2.html 等。 所以我想做什么。我想查找以www.example.com/products/开头的所有网址,并在这些网址中排除该区块。 到目前为止,我的一个网址的代码是:

<?php
$a = "www.example.com/products/product2";
$p = curPageURL(); ?>
<?php
 if($a == $p ){ 
    Dont show the block
?> 

但我有100个网址,我不会显示该块。 如果不写200行代码,是否有任何更改要对所有网址进行更改?

3 个答案:

答案 0 :(得分:1)

使用PHP strpos

此函数将检查URL中是否存在指定的字符串,如果存在,则不显示该块。

$findme = 'www.example.com/products/';
$pos = strpos($mystring, $findme);
if ($pos === FALSE) {
  // SHOW BLOCK
}

答案 1 :(得分:1)

尝试使用strpos()

$cururl= "http://.".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$pos = strpos($cururl, '/products/');
if ($pos !== FALSE) {
  // products found do your stuff
}

答案 2 :(得分:0)

我认为你可以使用in_array()这样的功能:

$blockedUrlArray[] = "www.example.com/products/product2";
$blockedUrlArray[] = "www.example.com/products/product3";
.
.
.
$searchUrl = curPageURL();

//if the current Url is not in blocked Urls
if(!in_array($searchUrl, $blockedUrlArray){
//do something 
}
//if the url is a blocked url
else{
//do something 
}
相关问题