How to determine page URL for if/else

General discussions related to php

Moderators: macek, egami, gesf

Hanscraft
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Jan 02, 2012 1:13 pm

How to determine page URL for if/else

Postby Hanscraft » Tue Jun 05, 2012 11:16 am

There are blocks on my Drupal website which are being called in based upon taxonomy terms. However, I'd like to have PHP look at the URL of the page that is within that taxonomy. If the URL is 'homework-help', then the block will not show.

I have tried using the following PHP code -- though it removes the block off all pages:


Code: Select all

if ($path = $_SERVER['REQUEST_URI']== 'homework-help' ) {
return FALSE;
} else {
return DL_block_show($taxonomies, $views);

Emy
New php-forum User
New php-forum User
Posts: 16
Joined: Sat Jun 02, 2012 8:16 pm

Re: How to determine page URL for if/else

Postby Emy » Tue Jun 05, 2012 5:58 pm

use preg_match or in_array

Hanscraft
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Jan 02, 2012 1:13 pm

Re: How to determine page URL for if/else

Postby Hanscraft » Wed Jun 06, 2012 6:34 am

So what I should be writing would look like:

Code: Select all

$in_array = '/homework-help';
if ($in_array == 'homework-help' ) {
return FALSE;
} else {
return DL_block_show($taxonomies, $views);

Emy
New php-forum User
New php-forum User
Posts: 16
Joined: Sat Jun 02, 2012 8:16 pm

Re: How to determine page URL for if/else

Postby Emy » Wed Jun 06, 2012 8:21 pm

You can even do like this:

Code: Select all

$myArray = array('homework-help', 'AnotherOne', 'YouCanAddMore');

$searchWord = 'homework-help';

if(in_array($searchWord, $myArray)
{
echo 'Done';
}
else
{
echo 'Try Later';
}


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest