Friday, March 26, 2010

Wildcards and current page marker in a...

For my horizontal and vertical nagivation menus I use PHP

includes. To mark the current page I have added this code

learned from David Powers' Dreamweaver and PHP books:

%26lt;?php if ($currentPage == 'foo.php') {echo

'class=''p7currentmark''';} ?%26gt;



The class p7currentmark assigns the menu entry a different

color.



Now I have modified my navigation in a way that one link in

the menu refers to a number of pages which are not part of

the menu but can accessed through links inside those pages.



How can modify my PHP code to have the menu entry marked for

all the pages. They are all stored in the same folder. I

thought I could use wildcards (% or *) and I tried but to no

avail. The only thing I achieved was using the logical

operator ''or'' (||). This worked. If there were only a few

pages I would use this type of code but there will be dozens

of pages in the end.



The file names of the pages in question partially all have

the same string: foo20070301.php, foo20070318.php,

foo20070326.php where the numbers after ''foo'' represent a

specific date. So the same string for all pages is

''foo2007''. Thus there is a logic behind the file names.



I hope I have expressed myself clearly.

Any help will be greatly appreciated.



Paul

Wildcards and current page marker in a...
Paul Westrich wrote:

%26gt; The file names of the pages in question partially all
have the same

%26gt; string: foo20070301.php, foo20070318.php,
foo20070326.php where the

%26gt; numbers after ''foo'' represent a specific date. So the
same string for

%26gt; all pages is ''foo2007''. Thus there is a logic behind the
file names.



If the foo2007 is always at the beginning of the name, use
this:



if (strpos($currentPage, 'foo2007') === 0) {echo
'class=''p7currentmark''';}



That's *three* equal signs.



--

David Powers, Adobe Community Expert

Author, ''Foundation PHP for Dreamweaver 8'' (friends of ED)

Author, ''PHP Solutions'' (friends of ED)


http://foundationphp.com/

Wildcards and current page marker in a...
David Powers schrieb:

%26gt; Paul Westrich wrote:

%26gt;%26gt; The file names of the pages in question partially
all have the same

%26gt;%26gt; string: foo20070301.php, foo20070318.php,
foo20070326.php where the

%26gt;%26gt; numbers after ''foo'' represent a specific date. So
the same string for

%26gt;%26gt; all pages is ''foo2007''. Thus there is a logic behind
the file names.

%26gt;

%26gt; If the foo2007 is always at the beginning of the name,
use this:

%26gt;

%26gt; if (strpos($currentPage, 'foo2007') === 0) {echo
'class=''p7currentmark''';}

%26gt;

%26gt; That's *three* equal signs.



Wonderful. That's it. It works like a charm. Again something

new learnt (learned).

Thanks a lot, David.

Paul



No comments:

Post a Comment