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'));
}
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 "
| Filename | Size |
| " .$file ." | " .filesize($file)/1024 ." kB | \n"; } echo "
Use it as the following:
list_files(”/home/test/files”);
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”
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";