Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: PHP Variable Arrays & Values in sNews  (Read 3186 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
PHP Variable Arrays & Values in sNews
« on: November 24, 2007, 03:58:41 PM »

sNews uses a few variable array functions. They are located at the top of the snews.php file in the default sNews 1.6 package. Variables are used in PHP to replace values (text, links, image file-paths and some html) that repeat often throughout all system functions. Having the variable arrays located in the top of the snews.php (engline) file makes it more convenient to change the values all in one place. Variable array functions... of course... can be located in other files as long as they are "included" to run along with the snews.php (engine) file.

Sample Variable Array Function: For example purposes, we will use a shortened (only 2 variable strings) version of the sNews db array function... used to set the database values used throughout the sNews engine functions in snews.php (and any other PHP function file you create for sNews use).

Quote

function db($variable) { // creates identity for all variables in the array
   $db = array(); // starts the array for PHP parsing
   $db['dbhost'] = 'localhost'; // first variable & value within the array
   $db['dbname'] = 'snewsdbase'// second variable & value within the array
   return $db[$variable]; // ends the array
   } // closes the function


All variable array functions have the same structure... by line:
1 - the first line gives the function its name, followed by its type (in the brackets) and the opening curly-bracket opens the function.
2 - the 2nd line defines the variable by name and opens the array.
3 & 4 - are just 2 variables with their values defined on the right side of the "equals" sign.
5 - closes the array.
6 - the closing curly-bracket closes the function.

Using the Variables in PHP functions:
The variable we use within PHP script is the actual variable-name. By example, the variable-name in the first variable string (in the example array above) is 'dbhost' and the value for this array (what the variable inserts in the script) is - localhost.

The actual variable inserted into PHP strings to display a value is formatted as:

Quote

db('dbhost'// inserts localhost where used

... and in most cases, you will see it wrapped within a set of single-quotes and dots (correct syntax) as:

Quote

'.db('dbhost').' // inserts localhost where used

You can create, add and use any variable array to sNews using the same general formatting rules for variables and their values.
« Last Edit: August 19, 2008, 03:01:50 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU