Ventrix’s Code Folds

php

Read all the raw data posted in a php script

by ventrix on Feb.04, 2009, under php

Read all the raw data posted in a php script

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
   $str = trim(file_get_contents('php://input'));
}
Leave a Comment : more...

PHP function for listing files with filesize

by ventrix on Oct.21, 2008, under php

function list_files($dir)
{
  if(is_dir($dir))
  {
    if($handle = opendir($dir))
    {
      echo "
\n";
          echo "


\n";
          while(($file = readdir($handle)) !== false)
      {
        echo "
\n";
                if($file != "." && $file != ".." && $file != "Thumbs.db" && is_file($file))
        {
          echo "


\n";
                }
                echo "

\n";
      }
          echo "
Filename Size
" .$file ." " .filesize($file)/1024 ." kB
\n"; closedir($handle); } } }

Use it as the following:
list_files(”/home/test/files”);

Leave a Comment more...

PHP function strip between tags

by ventrix on Oct.19, 2008, under php

I had to create a function which remove the tags and the text between them. It does not check for errors may occur.

function striptagspace($string,$tag1,$tag2)
{
	while(($start=strpos($string,$tag1))!==false)
	{
				$end=strpos($string,$tag2);
				$partone=substr($string, 0,$start);
				$parttwo=substr($string,$end+1,strlen($string));
				$string=$partone .$parttwo;
	}
	return $string;
}

Example:

$test="aloagd[aaaa]adgadg[bbb]asas";
echo striptagspace($test,'[',']');

will print “aloagdadgadgasas”

Leave a Comment more...

PHP script’s execution time

by ventrix on Oct.10, 2008, under php

An easy way to see how long it takes PHP to run a script:

1) Put this at the top of the page inside the php brackets

    $mtime = microtime();
    $mtime = explode(" ",$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $starttime = $mtime; 

2) Put other code and html

3) Put this code at the bottom of the page
    $mtime = microtime();
    $mtime = explode(" ",$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $endtime = $mtime;
    $totaltime = ($endtime - $starttime);
    echo "This page was created in ".$totaltime." seconds";
Leave a Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...