Showing posts with label PHP Functions. Show all posts
Showing posts with label PHP Functions. Show all posts

Monday 15 December 2014

get_class_methods PHP Function

array get_class_methods ( mixed $class_name )
Gets the class methods' names
Gets the class methods names.

<?phpclass myclass {
    
// constructor
    
function myclass()
    {
        return(
true);
    }

    
// method 1
    
function myfunc1()
    {
        return(
true);
    }

    
// method 2
    
function myfunc2()
    {
        return(
true);
    }
}
$class_methods get_class_methods('myclass');// or$class_methods get_class_methods(new myclass());

foreach (
$class_methods as $method_name) {
    echo 
"$method_name\n";
}
?>

5.0.0 As of PHP 5, this function returns the name of the methods as they were declared (case-sensitive). In PHP 4 they were lowercased. 4.0.6 The ability of specifying the object itself has been added.

Wednesday 3 December 2014

mysql_fetch_field - Get column information from a result

object mysql_fetch_field ( resource $result [, int $field_offset = 0 ] )
Get column information from a result and return as an object
Returns an object containing field information. This function can be used to obtain information about fields in the provided query result.

<?php
$conn 
mysql_connect('localhost''mysql_user''mysql_password');
if (!
$conn) {
    die(
'Could not connect to mysql server: ' mysql_error());
}
mysql_select_db('database'); //setup of database$result mysql_query('select * from table');
if (!
$result) {
    die(
'MySql Error: ' mysql_error());
}
/* get column metadata */$i 0;
while (
$i mysql_num_fields($result)) {
    echo 
"Information for column $i:<br />\n";
    
$meta mysql_fetch_field($result$i);
    if (!
$meta) {
        echo 
"No information available<br />\n";
    }
    echo 
"<pre>
blob:         
$meta->blob
max_length:   
$meta->max_length
multiple_key: 
$meta->multiple_key
name:         
$meta->name
not_null:     
$meta->not_null
numeric:      
$meta->numeric
primary_key:  
$meta->primary_key
table:        
$meta->table
type:         
$meta->type
unique_key:   
$meta->unique_key
unsigned:     
$meta->unsigned
zerofill:     
$meta->zerofill
</pre>"
;
    
$i++;
}
mysql_free_result($result);?>



Tuesday 2 December 2014

PHP mktime() Function - Get Unix timestamp for a date

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )
Get Unix timestamp for a date
Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.

<?php// Set the default timezone to use. Available as of PHP 5.1date_default_timezone_set('UTC');// Prints: July 1, 2000 is on a Saturdayecho "July 1, 2000 is on a " date("l"mktime(000712000));// Prints something like: 2006-04-05T01:02:03+00:00echo date('c'mktime(123452006));?>

5.3.0 mktime() now throws E_DEPRECATED notice if the is_dst parameter is used. 5.1.0 The is_dst parameter became deprecated. Made the function return FALSE on error, instead of -1. Fixed the function to accept the year, month and day to be all passed as zero. 5.1.0 When called with no arguments, mktime() throws E_STRICT notice. Use the time() function instead. 5.1.0 Now issues the E_STRICT and E_NOTICE time zone errors.

Syntax

mktime(hour,minute,second,month,day,year,is_dst);

ParameterDescription
hourOptional. Specifies the hour
minuteOptional. Specifies the minute
secondOptional. Specifies the second
monthOptional. Specifies the month
dayOptional. Specifies the day
yearOptional. Specifies the year
is_dstOptional. Set this parameter to 1 if the time is during daylight savings time (DST), 0 if it is not, or -1 (the default) if it is unknown. If it's unknown, PHP tries to find out itself (which may cause unexpected results).





Monday 1 December 2014

Strtolower - Returns string with all alphabetic characters converted to lowercase

string strtolower ( string $str )
Make a string lowercase
Returns string with all alphabetic characters converted to lowercase.

<?php
$str 
"Mary Had A Little Lamb and She LOVED It So";$str strtolower($str);
echo 
$str// Prints mary had a little lamb and she loved it so?>


14.-Curso PHP-MySQL. Formatear, cortar y unir strings.

Sunday 30 November 2014

PHP file_get_contents Function - Reads entire file into a string

string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
Reads entire file into a string
This function is similar to file(), except that file_get_contents() returns the file in a string, starting at the specified offset up to maxlen bytes. On failure, file_get_contents() will return FALSE.

<?php
$homepage 
file_get_contents('http://www.example.com/');
echo 
$homepage;?>

5.1.0 Added the offset and maxlen parameters. 5.0.0 Added context support.

PHP mail attachment - sending an attachment with PHP