PostNuke Help

Previous
pnVarPrepForDisplay

Home
up

Next
pnVarPrepForStore


pnVarPrepForOS

prepare variable for operating system

Synopsis

mixed pnVarPrepForOS(var, ...);

Description

pnVarPrepForOS() takes a variable number of filename arguments and for each one carries out suitable escaping of characters such that when used as part of an operating system filename it is valid and as close to the original string as possible.

Return Values

If pnVarPrepForOS() is only passed a single var argument then it returns the corresponding operating-system-ready variable. If pnVarPrepForOS() is passed multiple arguments then it returns an array of corresponding operating-system-ready variables.

Notes

If the parameter passed to pnVarPrepForOS() contains characters that are illegal for that operating system then they will be replaced with a suitable character (normally '_'). The directory separator ('/' on Unix systems, '\' on Windows systems) is considered one of these, and will be replaced. As such only filenames, and not pathnames, should be passed to this function.

This function does not need to be run on the content of files, just their names.

Running pnVarPrepForOS() multiple times is cumulative, and is not reversible unless the developer knows how many times it has been run. It recommended that variables that have been returned from pnVarPrepForOS() are only used in operating system functions, and then discarded.

Examples

// Get a version of name and number ready to use as directory and file names
list($osname, $osnumber) = pnVarPrepForOS($name, $number);
// Open file $topdirectory/$name/$number
$fh = fopen(pnVarPrepForOS($topdirectory) . "$osname/$osnumber", 'w');
       

Previous
pnVarPrepForDisplay

Home
up

Next
pnVarPrepForStore