PHP Problem

Status
Not open for further replies.

Rimmskinator

New Member
Dec 29, 2014
25
2
Hey everyone,

I've been working on a little project of mine and I've hit a problem (PHP)...
As this project will be released on the forums and on my website, I intend it to be very easy to customize.

So in my config file I have a few classes which are pretty much settings:
Code:
$site_name='Name Here';
$site_desc='My Site';
In this instance I will be using these two classes in every html title tag:
Code:
<title><?php echo $site_name ; ?> - <?php echo $site_desc ; ?></title>
But if the $site_desc=''; is empty I want it to automatically change to what I manually enter so I tried this:
Code:
<title><?php echo $site_name ; ?> - <?php echo $site_desc, ; else echo Index ; ?></title>
Hoping that if the $site_desc was empty it would say 'Index' or if I had it on about.php it would say About if I manually entered it?

Help?
 

GarettM

Posting Freak
Aug 5, 2010
833
136
Re-edited:
Incase the variable "$site_desc" does not exist you should check to see if its defined first and if its set, if its not then the answer above/rastas would spring a parse error.
try this:
PHP:
<title><?php echo $site_name; ?> - <?php echo (array_key_exists('site_desc', get_defined_vars()) && !empty($site_desc)) ? $site_desc : 'Index'; ?></title>
Example
 
Last edited:
Status
Not open for further replies.

Users who are viewing this thread

Top