|
|
|
| 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: 653 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 myCENTs:57.31 |
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: 653 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 myCENTs:57.31 |
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,314 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 myCENTs:14.53 |
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 | |||
|---|---|---|---|---|---|---|---|
![]() |
7 | Curt200518 | 267 | Yesterday, 10:29 PM Last post by: yordan |
|||
![]() |
32 | NilsC | 18,536 | 20th November 2009 - 12:15 PM Last post by: iG-topcathunter |
|||
![]() |
5 | PigFat | 2,240 | 16th November 2009 - 11:31 PM Last post by: iG-Demonz Media |
|||
![]() |
14 | kanade | 4,273 | 12th November 2009 - 07:55 PM Last post by: iG-Ram |
|||
![]() |
5 | dungsport | 2,660 | 12th November 2009 - 07:09 AM Last post by: Quatrux |
|||
![]() |
14 | rapco | 8,007 | 6th November 2009 - 07:14 AM Last post by: iG-Rajeesh |
|||
![]() |
0 | Swisoon | 117 | 30th October 2009 - 02:18 PM Last post by: Swisoon |
|||
![]() |
6 | szupie | 2,784 | 30th October 2009 - 01:06 PM Last post by: Quatrux |
|||
![]() |
5 | starscream | 70 | 30th October 2009 - 07:31 AM Last post by: starscream |
|||
![]() |
14 | PureHeart | 10,032 | 30th October 2009 - 03:45 AM Last post by: iG-butter1093 |
|||
![]() |
17 | vdhieu84 | 6,908 | 29th October 2009 - 07:44 PM Last post by: iG- |
|||
![]() |
4 | yordan | 232 | 29th October 2009 - 11:29 AM Last post by: iG-Oobles |
|||
![]() |
23 | WeaponX | 4,018 | 26th October 2009 - 01:31 PM Last post by: iG-computerwiz9001 |
|||
![]() |
14 | Grafitti | 3,089 | 26th October 2009 - 06:34 AM Last post by: iG-Khalid Mehmood Awan |
|||
![]() |
12 | avalon | 4,203 | 23rd October 2009 - 10:15 AM Last post by: iG-kkk |
|||
|
Lo-Fi Version | Time is now: 24th November 2009 - 09:52 PM |
© 2009 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





