Page 1 of 1

How do I test a variable against each entry in an array?

Posted: Thu Oct 26, 2006 8:52 am
by adders
Hello All

Does anyone know how I can test a variable against each entry in an array.

I will have code loosely like this:

Code: Select all

<head>
$url = substr($_SERVER['REQUEST_URI'],1);;
$nodisplay = "vos_new/index.php?option=com_frontpage&Itemid=1";
</head>
<body>
   <?php
            if ($nodisplay == $url)
               {
               return;
               }
            else
               {
               mosLoadModules ( 'header', -2);
               } 
   ?>
</body>
I would like to be able to store multiple values in $nodisplay, then check $url against each in turn and if it matches any of them I want to exit the script without running mosLoadModules.

Alternatively creating a URL pattern might work so if someone knows how to do that and store it in a variable that might be useful also.

Thanks

Adders

Posted: Thu Oct 26, 2006 9:09 am
by kaszu

Code: Select all

<head>
</head>
<body>
   <?php
           $url = substr($_SERVER['REQUEST_URI'],1);
           $nodisplay = Array("vos_new/index.php?option=com_frontpage&Itemid=1", "index.php?something=else", "...");

            if (!in_array($url, $nodisplay))
               mosLoadModules ( 'header', -2);
   ?>
</body>

Posted: Thu Oct 26, 2006 9:14 am
by adders
Thanks Kaszu.

You've been a great help today.

Cheers

Adders

Posted: Thu Oct 26, 2006 10:18 am
by adders
OK - I promise this is the last question today.

With regard to this query, what would I do if I want to match part of a URL (I would have several of these partial URLs stored in my array).

In this case anything with index.php?option=com_joomlaboard&Itemid=27&func=post in it (or at the start of it).

So that for example my code would run on this page:

index.php?option=com_joomlaboard&Itemid=27&func=view&catid=43&id=27180#27180

But not on this page:

index.php?option=com_joomlaboard&Itemid=27&func=post&do=edit&id=27180&catid=43

If you guys can help with this I promise never to darken your doors again (well not for the rest of the day anyway).

Cheers

Adders

Posted: Fri Oct 27, 2006 4:06 am
by adders
Anyone got any ideas on the above?

Cheers

Adders

Posted: Fri Oct 27, 2006 4:20 am
by volka
foreach and strncmp might do the trick.

Posted: Fri Oct 27, 2006 11:32 am
by adders
Cheers mate I'll take a look.

Thanks

Adders