Thursday, August 11, 2011

PHP JSON

Hi friends,
If we want to get data from an url which .json format, here is the code..
$url = "yoururl.json";
$json = @file_get_contents($url);
$statuses = json_decode($json);

Now the all details in that url will be in variable $statuses .

If suppose we to get data from HTML tag which is named text

$status_text = $statuses->text;
If we are having number of text tag and we want 1st tag we have to mention as array
$status_text = $statuses[0]->text;

If we want to get value from element which is inside the element user then

$name = $statuses[0]->user->text;

Wednesday, August 3, 2011

Delete Files and folder and inside folder files using php - Clear Buffer

Delete Files and folder Using php:

html page:

< align="right"><small><a href="/clear.php?p=/var/www/checklist">clear buffer</a></small></div>


Clear.php :

<?php
if (isset($_REQUEST["p"]))
{
$paths = $_REQUEST["p"];
}
@$deldir = deletefolder($paths);
function deletefolder($paths)
{
if ($handlerm=opendir($paths))
{
while (false!==($filerm=readdir($handlerm)))
{
if ($filerm<>"." AND $filerm<>"..")
{
if (is_file($paths.'/'.$filerm))
{
@unlink($paths.'/'.$filerm);
}
if (is_dir($paths.'/'.$filerm))
{
deletefolder($paths.'/'.$filerm);
@rmdir($paths.'/'.$filerm);
}
}
}
}
closedir($dhvalid1);
}
echo "< style='color:red'>Successfully cleared</h1>";
?>