milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. PHP
  4. PHP

Save XML in human readable format

Details
Written by: Stanko Milosev
Category: PHP
Published: 22 September 2008
Last Updated: 30 November -0001
Hits: 4778

With using DomDocument class.

 

Like this:

<?
$sXML = '<root><element><key>a</key><value>b</value></element></root>';
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
$doc->loadXML($sXML);
echo $doc->saveXML();
?>

From here.

NuSOAP

Details
Written by: Stanko Milosev
Category: PHP
Published: 09 September 2008
Last Updated: 30 November -0001
Hits: 4238
In queries can't be unicode characters, at least, I couldn't find way to do it. Of course, in a result can be unicode characters as I already described. Also, it is very important how do you save your unit, if it is saved as unicode, again, you will have problems.

Passing $_POST variable to redirected page.

Details
Written by: Stanko Milosev
Category: PHP
Published: 08 September 2008
Last Updated: 18 July 2011
Hits: 4422

If you need to redirect page and pass $_POST variable (or any other variable) you should use following code:

 

<?php
  header("HTTP/1.0 307 Temporary redirect");
  header("Location: http://localhost/test.php");
?> 

List all files in a directory tree.

Details
Written by: Stanko Milosev
Category: PHP
Published: 03 September 2008
Last Updated: 03 March 2015
Hits: 4541
I am too lazy, I know.

Here is recursive way:

<?php
	function rec_listFiles( $from = '.')
	{
		if(! is_dir($from))
		return false;

		$files = array();
		if( $dh = opendir($from))
		{
			while( false !== ($file = readdir($dh)))
			{
				// Skip '.' and '..'
				if( $file == '.' || $file == '..')
				continue;
				$path = $from . '/' . $file;
				if( is_dir($path) )
				$files += rec_listFiles($path);
				else
				$files[] = $path;
			}
			closedir($dh);
		}
		return $files;
	}
?>
And here is iterative:
<?php
	function listFiles( $from = '.')
	{
		if(! is_dir($from))
		return false;
		$files = array();
		$dirs = array( $from);
		while( NULL !== ($dir = array_pop( $dirs)))
		{
			if( $dh = opendir($dir))
			{
				while( false !== ($file = readdir($dh)))
				{
					if( $file == '.' || $file == '..')
					continue;
					$path = $dir . '/' . $file;
					if( is_dir($path))
					$dirs[] = $path;
					else
					$files[] = $path;
				}
				closedir($dh);
			}
		}

		return $files;
	}
?>
Searching for a file in a directory tree:
<?php
	function rec_listFiles( $fileName, $from = '.', &$pathOut)
	{
		if ($pathOut != '')
			return true;
		else
		{

			if(! is_dir($from))
				return false;

			if( $dh = opendir($from))
			{
				while( false !== ($file = readdir($dh)))
				{
					// Skip '.' and '..'
					if( $file == '.' || $file == '..')
						continue;
					$path = $from . '/' . $file;
					if( is_dir($path) )
					{
						//echo $path.'<p/>';
						rec_listFiles($fileName, $path, $pathOut);
					}
					else
					{
						if ($fileName == $file)
						{
							$pathOut = $path;
						}
					}
				}
			closedir($dh);
			}
			if ($pathOut == '')
				return false;
			else
				return true;
		}
	}

	$pom = '';
	if (rec_listFiles('mod_newsflash.php', '.', $pom))
	echo $pom;
	else
	echo 'Could not find file.';
?>
  1. NuSoap
  2. Instalation PHP 5.2.6 on Windows XP IIS
  3. Parametrized query
  4. Saving file.

Page 2 of 4

  • 1
  • 2
  • 3
  • 4