Tuesday, May 19, 2009

Using PHP's Built-in Source Highlighter

PHP offer two functions for highlighting PHP code: highlight_file() and highlight_string(). Both functions return the same results, but each has its own specific input parameters. As their names suggest, the first function takes the filename of the PHP script whose code is to be highlighted, while the second takes the input as a string.

A Quick Example

Let's take a look at an example of the highlight_string() function in action:

include_once 'init.inc.php';

if (!empty($_POST['text'])){

echo '

';
highlight_string($_POST['text']);
echo '
';
}
?>

" method="post">




Monday, May 18, 2009

array to file

Code reads an array and writes array's php code to a file.
Inputs:array_to_file($array array,$arrayname string,$filename string)
Returns:none (writes file)


/* Array to File */
function __process_array($array,$indent)
{
$ret_str = "";
$first = true;
foreach ($array as $key => $value)
{

if (!$first)
$ret_str .= ",\n";
else
$first = false;

$ret_str .= str_repeat(" ",$indent);

if (is_array($value))
{
$ret_str .= "'$key' => array(\n".__process_array($value,$indent+5)."\n".str_repeat(" ",$indent).")";
}
elseif (is_string($value))
{
$ret_str .= "'$key' => '$value'";
}
elseif (is_int($value))
{
$ret_str .= "'$key' => $value";
}
elseif (is_bool($value))
{
$ret_str .= "'$key' => ".($value?"true":"false");
}
}
return $ret_str;
}

function array_to_file($array,$name,$filename)
{
$file_str = "
$file_str .= __process_array($array,6);
$file_str .= "\n );\n?>";

$file = fopen($filename,"w");
fwrite($file,$file_str);
fclose($file);
}
?>

Excel Format AS400

If you specify TOFMT(*XLS), CVTDBFSTMF will create an Excel (™) spreadsheet from your database file. The default is to create a BIFF 8 file (compatible with Excel 97, Excel 2000, Excel XP and above). Alternatively, you can choose to create a BIFF 5 file (compatible with Excel 5.0 and above) if your spreadsheet does not support the latest Excel file format.

Files created by CVTDBFSTMF in Excel format can be opened directly by any application with supports the Excel file format, including Microsoft Excel but many others besides, such as Lotus 123 and MS Works spreadsheet.

The Integrated File System (IFS)

#navbar-iframe {
display: none !important;
}

The iSeries Integrated File System (IFS) provides a coherent, coordinated set of file systems which can used for storing a variety of data physically on the iSeries or for communicating with file systems on other platforms.

These files systems include the following that may be of use to you for storing stream files created by CoolSpools or Slipstream locally on your iSeries or remotely on another computer (PC, UNIX server etc.)

"root" The "root" (/) file system. This file system takes full advantage of the stream file support and hierarchical directory structure of the integrated file system. The root file system has the characteristics of the Disk Operating System (DOS) and OS/2 file systems. You should typically use the root file system if you want to store stream files created by CoolSpools or Slipstream locally on the same iSeries where you run the CVTDBFSTMF command.

QNTC Windows NT Server file system. This file system provides access to data and objects that are stored on a PC running Windows NT 4.0 or higher. It allows iSeries server applications to use the same data as Windows NT clients. If you prefer not to store stream file locally on your iSeries, you can use QNTC to enable CoolSpools or Slipstream to write stream files directly to a PC running NT, Windows 2000, Windows XP etc. instead. This can be an effective way of sharing data created by CoolSpools or Slipstream amongst your users and customers.

NFS Network File System. This file system provides you with access to data and objects that are stored on a remote NFS server. An NFS server can export a network file system that NFS clients will then mount dynamically. This may be an option for sending stream files to a UNIX server.

QNetWare The QNetWare file system. This file system provides access to local or remote data and objects that are stored on a server that runs Novell NetWare 4.10 or 4.11 or to standalone PC Servers running Novell Netware 3.12, 4.10 4.11 or 5.0. You can dynamically mount NetWare file systems over existing local file systems.

QOpenSys The open systems file system. This file system is compatible with UNIX-based open system standards, such as POSIX and XPG. Like the root file system, this file system takes advantage of the stream file and directory support that is provided by the integrated file system. In addition, it supports case-sensitive object names.

QDLS The document library services file system (previously know as “shared folders”). This file system provides access to documents and folders. Use this file system only if you have applications which require it. QDLS is significantly slower and has major limitations (e.g. in relation to naming) compared with the root file system.

QFileSvr.400 The QFileSvr.400 file system provides access to other file systems that reside on remote iSeries servers. You can use QFileSvr.400 to save output from CoolSpools or Slipstream directly to another iSeries.

See http://publib.boulder.ibm.com/iseries/v5r1/ic2924/info/rzaia/rzaiacon.htm for full details of the Integrated File System.

We will now focus a little more closely on the QNTC File System since this is little known area of iSeries functionality which may well be of serious interest to users of CoolSpools and Slipstream.

QNTC

The QNTC file system is a subdivision of the IFS (Integrated File System) that enables the iSeries to access file and device shares (e.g. printers and CDROM) drives on a remote NT system. Please note that contrary to a commonly held fallacy this is NOT restricted to the Integrated NetFinity Server (aka IPCS or FSIOP).

Using the QNTC file system, your iSeries can read and write files that reside physically on a PC running Windows NT 4 or above. This means that CoolSpools or Slipstream can output stream files directly to an NT server if you would prefer to store them there rather than in the root file system of your IFS.

To use QNTC, the only software you need other than the base operating system is TCP/IP Connectivity Utilities for iSeries 400 (S722-TCl). However, setting up QNTC can be tricky. For full setup information, refer to the article in the IBM Software Knowledgebase at http://www-912.ibm.com/s_dir/slkbase.nsf/1ac66549a21402188625680b0002037e/aea450153eebf8ff8625670f0072550f?OpenDocument&Highlight=0,QNTC

However, here is a quick overview of the steps you need to follow to set up QNTC. This example relates to V5R1.

  1. First you must ensure that the domain name defined by your iSeries NetServer configuration matches your PC’s Windows network workgroup name. NetServer is the function on the iSeries that provides support for the Windows Network Neighbourhood. You can use Operations Navigator (OpsNav) to setup and manager NetServer. From the main OpsNav window, click the name of your machine, select File Systems, and then right-click File Shares. Choose Open iSeries NetServer from the menu to display the NetServer window. Right-click iSeries NetServer and choose Properties to display the Properties window, where you can change the domain. Click the General tab and press the Next Start button. A window appears where you can set properties that will be used the next time NetServer is restarted. In the domain name field, enter a name that matches the workgroup of the NT PC that you wish to access. Then end and restart NetServer by clicking the Stop icon followed (once NetServer has fully ended) by the green triangle icon.

  2. One other thing which must match between the iSeries and the NT PC is the user id and password you’re going to use. It is vital that your iSeries user id be recognised by the NT PC as a valid network logon id, and that the passwords are the same on both the iSeries and the NT machine. It may well be advisable to create a special user id on the two platforms specifically for the purpose of communicating between them using QNTC. You can then ensure that when the password needs to be changed, it is changed on both systems, if this needs to be done manually.

  3. On the PC (running Windows NT, 2000, XP etc.), select Start, Settings, Control Panel, and System. Then choose the Network Identification tab, click the Properties button, select Workgroup, and set the workgroup to match the domain that NetServer on the iSeries was configured to use. Note that you may have to reboot the PC for these changes to take effect. To test your connection, first ensure that you are logged on to the iSeries using a shared user id/password (see above), then run the command WRKLNK '/QNTC/*' on the iSeries. This could take several minutes to complete the first time it is run. Your NT system should appear on the list. If it doesn't, you may be able to manually establish a connection to the NT system using command CRTDIR /QNTC/ ‘, substituting the name of your NT system for servername. Find your NT system in this list and choose Display (option 5) in WRKLNK (Work with Object Links) to display your file shares on NT. If the file shares don't appear, double-check that your user IDs and passwords match exactly on both systems.

You access the QNTC file system by including QNTC and the name of your PC and share name in the path name you specify on TOSTMF (To Stream File) parameter of the CVTDBFSTMF command.

For example, let’s imagine you have a company server running Windows NT 4 or above and you have decided that this is a convenient place to save the output from CoolSpools or Slipstream so that all of your users can have shared access to the data. Let’s imagine that this server is called NTServer and that it has a file share name set up called NTFiles. Below the share name, there is a directory called CustData. If you wanted to convert data from your customer file and save it as an Excel spreadsheet in this location under the file name customer_file.xls, you would run a command something like this:

CVTDBFSTMF FROMFILE(custfile)

TOSTMF(‘/QNTC/NTServer/NTFiles/CustData/customer_file.xls’)

TOFMT(*XLS)

Slipstream AS400

Slipstream helps IBM iSeries sites deliver high-quality information to their customers and users more quickly and more simply than was possible previously.

Slipstream does this by providing tools for exporting iSeries database tables as PC-format stream files such as Excel spreadsheets, CSV, text and HTML. It also integrates with Query/400, QM/400 and SQl to let you save the output from those functions in Excel and other formats

Do you run queries and still produce the output on paper and have to distribute it through the mail? With Slipstream, without changing your query and with just a single extra command, you you can run the query, save the output as a native Excel spreadsheet and email it to your users or save it on a server for easy access!

The iSeries database (UDB for iSeries) is an advanced, function-rich, easily managed relational database allowing large quantities of data to be stored securely and retrieved and updated rapidly and efficiently. However, today, many of our customers and users want to be able to access and manipulate the data held in that database using tools such as spreadsheets, PC databases and Business Intelligence tools. Enabling their customers and users to access data held on the iSeries in the form in which they need it is a challenge that many iSeries sites face on daily basis.

Slipstream provides a innovative solution to this problem. With Slipstream you can create PC-format files from your iSeries database files right on the iSeries itself. You can also turn the laborious process of running a query and getting the output into a spreadsheet into a simple one-step operation.

Let's have a closer look at why your should choose Slipstream.