//Returns an array with properties of an object
function GetAnArrayOfPropertiesForAnObject($Object)
{
$arrayProperties = get_object_vars( $Object);
foreach($arrayProperties as $key=>$value)
{
$returnArray[] = strtolower($key);
}
return $returnArray;
}
How to write code in C#, Asp.Net, Php, Javascript, C. On this blog you will find example codes that will help you to understand concepts of programming.
Showing posts with label Php. Show all posts
Showing posts with label Php. Show all posts
Monday, February 27, 2012
How to get an array with properties of an object in Php?
If you ever need to get an array of properties for an object in php this is the method that I created and might help you with that. The key is to use get_object_vars() method, parse each key and memorize in an array.
Monday, February 20, 2012
How to verify if checkbox was checked in PHP after submit?
Often when you have a form in a html file(might be even php file as you might know) and submit to a php file you want to see if checkbox from your form was checked so you will save in your database accordingly some value.
I have a form like this:
<form name="AddUser" method="post" action="createUser.php">
<fieldset>
<legend>Add a user </legend>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" />
<br/>
<label for="newsletter">Subscribe to newsletter:</label>
<input type="checkbox" name="newsletter" id=" newsletter " value="" />
<br/>
<input type="submit" name="add_user_btn" value="Create" />
</fieldset>
</form>
As usually the solution is simple, using isset() method:
I have a form like this:
<form name="AddUser" method="post" action="createUser.php">
<fieldset>
<legend>Add a user </legend>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" />
<br/>
<label for="newsletter">Subscribe to newsletter:</label>
<input type="checkbox" name="newsletter" id=" newsletter " value="" />
<br/>
<input type="submit" name="add_user_btn" value="Create" />
</fieldset>
</form>
As usually the solution is simple, using isset() method:
if(isset($_POST['newsletter'])) $newsletter= 1; else $newsletter= 0;
Monday, January 16, 2012
How to fix permissions for files on a server?
Often after you upload files on a server you will get to the point when you won't be able to edit/delete add other files. It happened to me when I unzipped an archive directly on server with a php file.
So how do we change attributes?
So how do we change attributes?
set_time_limit ( 0 );
ini_set("memory_limit","1000M");
file_fix_directory(dirname(__FILE__));
function file_fix_directory($dir, $nomask = array('.', '..', 'CVS')) {
if (is_dir($dir)) {
// Try to make each directory world writable.
if (@chmod($dir, 0777)) {
echo "Made writable: " . $dir . "
";
}
}
if (is_dir($dir) && $handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (!in_array($file, $nomask) && $file[0] != '.') {
if (is_dir("$dir/$file")) {
// Recurse into subdirectories
file_fix_directory("$dir/$file", $nomask);
}
else {
$filename = "$dir/$file";
// Try to make each file world writable.
if (@chmod($filename, 0777)) {
echo "Made writable: " . $filename . "
";
}
}
}
}
closedir($handle);
}
}
Subscribe to:
Posts (Atom)