Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP string does not contain

Tags:

php

What I am trying to do is to display a message (1) if the current link does not contain the words "index" or "/?"

I found this to do the direct opposite:

$page = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($page, 'index.php') !== false xor strpos($page, '/?') !== false) {
    echo '1';
} else {
    echo '2';
}

This code displays "2" on pages where there is no "index" or "/?" in the link, but I need the opposite: display "1" where there is no "index" or "/?" in the link.

BTW I have tried all combinations: !strpos, TRUE, !==, but it doesn't seem to work for me. I need a way without the "else" in the code, otherwise I could just change up the echos.

like image 958
10now Avatar asked Mar 19 '13 11:03

10now


1 Answers

$page = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($page, 'index.php') === false && strpos($page, '/?') === false) 
{
    echo"1";
}
else
{
    echo"2";
}

Should display 1 if there's no index.php or /? in $page

like image 166
Stu Avatar answered Oct 05 '22 06:10

Stu