|
|
|
| Web Hosting Guide |
![]() ![]() |
Display Text If Line Not Empty In Config File |
Feb 5 2006, 04:17 AM
Post
#1
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
I have been working on a new template and I would like it so that if in the global configuration file, I have a variable for a global site announcement that would go on every page.
The line in the global configuration file is this: CODE $announcement = "ANNOUNCEMENT"; In my template file, I could easily add CODE <?php echo $announcement; ?> but that would leave a blank space and with the announcement style (similar to the Invision Power Board error box). Is there some sort of script that could be put in the template page so I could have the global config file look something like this: CODE //Turn on announcement; 1 means on, 0 means off $announcementOn = 1 //Announcement Text: $announcement = "Blah" Basically, if there is a "1" on $announcementOn, it enables code that echos the stylesheet class and displays the announcement in $announcement so when any page is displayed on the site, the announcement is shown. Thanks for any help! [N]F |
|
|
|
Feb 5 2006, 04:24 AM
Post
#2
|
|
|
Hedonist at large Group: Members Posts: 610 Joined: 30-July 05 From: another realm Member No.: 7,524 |
You could try:
CODE <?php if(isset($Announcement)) echo $Announcement; ?> That should be sufficient, you don't need to add another variable. |
|
|
|
Feb 5 2006, 10:06 AM
Post
#3
|
|
|
Making IT Happen Group: Members Posts: 678 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 myCENTs:69.15 |
Is it possible you could show how your output looks?
I'm trying to understand what you want in your last request: CODE <?php $announcementOn = true; $announcement = 'blah'; ?> <?php if($announcementOn) echo $announcement; else{ ...do whatever you want... } ?> I don't think I fully understood what you wanted, or why you have a mysterious blank, is this because $announcement is empty/null? Cheers, MC |
|
|
|
Feb 5 2006, 05:41 PM
Post
#4
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
QUOTE(mastercomputers @ Feb 5 2006, 06:06 AM) I don't think I fully understood what you wanted, or why you have a mysterious blank, is this because $announcement is empty/null? Cheers, MC [right][snapback]68900[/snapback][/right] I don't have a mysterious blank... However, I think what abhiram suggested *MIGHT* work. I think this is how I would set it up on my template page: CODE <?php if(isset($announcement)) echo "<p class=\"announcement\">$announcement</p>"; ?> Does that look correct? [N]F |
|
|
|
Feb 6 2006, 08:33 PM
Post
#5
|
|
|
Premium Member Group: Members Posts: 292 Joined: 15-December 04 Member No.: 1,768 |
Looks like it would work to me. If $announcement is not set then you don't display anything, if it is you do. You could also use
CODE if(!empty($announcement)) or CODE if($announcement) an item is considered set in the following circumstance CODE $announcement = ""; Kinda good to know I s'pose. |
|
|
|
Feb 7 2006, 02:14 AM
Post
#6
|
|
|
Hedonist at large Group: Members Posts: 610 Joined: 30-July 05 From: another realm Member No.: 7,524 |
I guess minnieadkins is right. Thanks ... that's something I didnt' know. I thought 'empty=not set'.
|
|
|
|
Feb 8 2006, 01:51 AM
Post
#7
|
|
|
Making IT Happen Group: Members Posts: 678 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 myCENTs:69.15 |
If that's supposedly correct then this would be your method:
CODE <?php if( isset($announcement) && !empty($announcement) ){ echo '<p class="announcement">' . $announcement . '</p>'; } ?> isset, checks if the variable is created, does not check it's contents, !empty checks for content. !empty, checks if the variable has information, if it didn't pass the isset it will not do this expression, so the variable must exist first. You should not do if($announcement), as you need to check if the variable exists before performing anything on it. This will result in a warning if the variable does not exist. Cheers, MC |
|
|
|
Mar 21 2006, 09:29 AM
Post
#8
|
|
|
Member [ Level 1 ] Group: Members Posts: 42 Joined: 17-March 06 From: Russia, St.Petersburg Member No.: 12,058 |
simply,
CODE <?php
include("config.cfg"); if($announcementOn) { if($announcement) { print $announcement; } else { print "No announcement!"; } } ?> This post has been edited by CrazyPensil: Mar 21 2006, 09:30 AM |
|
|
|
Mar 21 2006, 03:12 PM
Post
#9
|
|
|
the Q Group: [HOSTED] Posts: 1,355 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 myCENTs:82.09 |
Well, I would do like mastercomputers suggested it, because it is not recommended to do it like you showed above. But why use empty and isset at the same variable (a comment for mastercomputers) I saw people do it like this too, they said that this is just their programming style.. empty also checks if the variable is set (or better saying, that it does not throw a warning error if the variable is not set) and checks if it is == "" or 0 or "0" or NULL or FALSE or array()
so I would do it: CODE <?php if ( !empty($announcement) ) { echo '<p class="announcement">' . $announcement . '</p>'; } ?> everything clearly is written here: http://php.net/empty but anyway, I think this is to simple, to discuss it |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
3 | PerfecTiion | 588 | 4th March 2010 - 10:57 AM Last post by: yordan |
|||
![]() |
37 | snutz411 | 9,282 | 3rd March 2010 - 10:20 PM Last post by: John Heinl |
|||
![]() |
18 | vicky99 | 7,576 | 24th February 2010 - 08:16 PM Last post by: iG-ivmai |
|||
![]() |
11 | szupie | 3,842 | 23rd February 2010 - 10:22 PM Last post by: HannahI |
|||
![]() |
7 | FirefoxRocks | 5,032 | 23rd February 2010 - 03:16 PM Last post by: iG-Patfreeze |
|||
![]() |
17 | kc8ual | 3,028 | 23rd February 2010 - 06:29 AM Last post by: Quatrux |
|||
![]() |
17 | Jimmy89 | 4,818 | 23rd February 2010 - 12:36 AM Last post by: iG-David |
|||
![]() |
5 | jackpinerepublic | 4,390 | 19th February 2010 - 02:04 AM Last post by: iG-Simon Varley |
|||
![]() |
7 | Eggie | 161 | 15th February 2010 - 10:34 PM Last post by: Nelson Blogs |
|||
![]() |
17 | rapco | 9,923 | 12th February 2010 - 06:48 AM Last post by: iG-Sanjaya |
|||
![]() |
22 | victorhu | 7,816 | 11th February 2010 - 05:13 AM Last post by: iG-Shane |
|||
![]() |
15 | PureHeart | 11,910 | 10th February 2010 - 08:02 PM Last post by: iG-khadeer |
|||
![]() |
14 | jedipi | 7,765 | 10th February 2010 - 05:47 PM Last post by: iG-keith |
|||
![]() |
12 | Nqon | 4,595 | 9th February 2010 - 02:46 PM Last post by: iG- |
|||
![]() |
10 | tansqrx | 8,283 | 9th February 2010 - 12:50 PM Last post by: iG-gagan deep singh |
|||
|
Lo-Fi Version | Time is now: 20th March 2010 - 05:15 PM |
© 2010 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Feb 5 2006, 04:17 AM






