Showing posts with label Php. Show all posts
Showing posts with label Php. Show all posts

PHP 5.3 coming June 30th

From the 'whatever happened to PHP 6?' files:

PHP 5.3 could be out as soon as Tuesday June 30th. The new open source language release is a big deal for a lot of reasons, not the least of which is the fact that by my count this is the first major update to PHP since 2006 and the PHP 5.2 release.

PHP 5.3 is also interesting in that it includes at least one key feature that was originally intended for PHP 6 (whenever -- if ever -- that release will be out).

I spoke with Zeev Suraski, co-founder and CTO at commercial PHP vendor Zend Technologies last month about PHP 5.3. He noted that one key feature backported from PHP 6 into PHP 5.3 is namespaces, which is a way to encapsulate classes and other PHP items more easily.

While the official release is on June 30th, support for PHP 5.3 is already present in development tools from Eclipse released this week.

*UPDATE JUNE 30TH - PHP 5.3 did get released - full story is up on the main site.

The Eclipse Galileo release include the PHP Development Tools 2.1 (PDT) application which has PHP 5.3 support. Zend which backs the PDT effort, now has a commercial tool in beta that builds on the PDT 2.1 release as well.

Zend Studio 7.0 is currently in Beta and according to Zend also includes new enhanced source code editing for PHP as well as improved integration with the Zend Framework. By my count, the Zend Studio 7.0 beta is the first major upgrade to Zend Studio and a year and half when Zend pushed out its first IDE based on Eclipse.

The new PHP 5.3 release is coming at a critical time for the PHP community in my opinion. It is continuing to face pressure on the web development side from Ruby and in the enterprise space, .NET and Java are evolving themselves as well.

Why PHP 6 has not been released yet is a question that I ask PHP language developers often and regularly. While PHP 5.3 is not the big evolution that PHP 6 might end up being, PHP 5.3 is likely a key incremental step in the evolution of PHP. more

Running file as background process

All your scripts from a shell as a background process in PHP

exec ("/usr/bin/php yourscript.php >/dev/null &");
The part on the end is the important part... >/dev/null sends the output if your script to nowhere and the & spins it into a background process.

Static Variable and Functions

Static Variables:
1. Only one instance of a given variable exists for a class.
2. Can be accessed without the instace object
3. Can be accesable through any methods(static or nonstatic)

Static functions:
1. Can be called by prefixing the class name to the method
eg: int val = class.method();
2. No need to instanciate the class.

Some interesting Bugs in php

<?
if(isset($_REQUEST['submit']))
echo "<pre>";
print_r($_POST);
echo "</pre>"

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="POST">
<input type="hidden" name="test.one" value="1" />
<input type="hidden" name="test#two" value="2" />
<input type="submit" name="submit Me" value="Click me" />
</form>

</body>
</html>

<?
echo date('Y-m-d', strtotime('first monday jan 2007'));
echo "<br>";

echo date('Y-m-d', strtotime('first monday feb 2007'));
echo "<br>";

echo date('Y-m-d', strtotime('first thursday feb 2007'));
echo "<br>";

echo date('Y-m-d', strtotime('first thursday jan 2007'));
echo "<br>";
?>

<?
preg_match('/(.{0,20})$/us', " ", $m);
var_export($m);
?>

<?
for ($char="A";$char<="Z";$char++)
{
echo "$char - ";
}
?>

<?
$test = "X\\X?asdasdasd\\asdasd.*";

echo $tt=preg_quote($test);
//echo preg_match("/X\\X/", $tt)."\n";
?>

pregquote

<?
$test = "X\\X?asdasdasd\\asdasd.*";

echo $tt=preg_quote($test);
//echo preg_match("/X\\X/", $tt)."\n";
?>

Php Questions...

1.How can we know the number of days between two given dates using mysql? select DIFFDATE( NOW(), 'yyyy-mm-dd' );

2.How can I load data from a text file into a table?
The mysql provides a LOAD DATA INFILE syntax. U can load data from a file.

3.What is meant by MIME?
Multipurpose Internet Mail Extensions. WWW's ability to recognise and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types. ...

4.What are the difference between abstract class and interface?
Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.
Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

batch file with php

How to run window batch file in php?
Step 1
Creata bacth file like that

mkdir %1

save the file name as test.bat


step-2

php program
<?
shell_exec("test.bat india");
?>

Run the php automaticaly create one floder

php Substring Examples

Use substr( ) to select your substrings:

$substring = substr($string,$start,$length);
$username = substr($_REQUEST['username'],0,8);

Php Questions

Object-oriented questions

  1. Class definitions must end with a semi-colon: true or false?

    True
    False


  2. Calling __clone() is not allowed: true or false?

    True
    False


  3. Abstract classes cannot be instantiated: true or false?

    True
    False


  4. You can use objects as an array in foreach loops: true or false?

    True
    False


  5. Private variables can only be accessed from within the class that defined them, or any subclass of it: true or false?

    True
    False


Function questions

  1. What function would you use to tell the browser the content type of the data being output?

    imagejpeg()
    imageoutput()
    flush()
    header()
    imageload()


  2. What parameters does the func_get_args() function take?

    0: It doesn't take any parameters
    1: name of function to check
    2: name of function to check, boolean "count optional arguments"


  3. What does the array_shift() function do?

    Add an element to an array
    Removes an element from an array
    Shifts all elements towards the back of the array
    Switches array keys and values
    Clears the array


  4. What function would you use to delete a file?

    unlink()
    delete()
    fdelete()
    file_delete()


  5. What is the difference between exec() and pcntl_exec()?

    Nothing, they are the same
    pcntl_exec() forks a new process
    pcntl_exec() can only be called from a child process
    None of the above


  6. If $string is "Hello, world!", how long would the output of sha1($string) be?

    It varies
    16 characters
    20 characters
    24 characters
    32 characters
    40 characters


  7. If the input of chr() is $a and the output is $b, what function would take input $b and produce output $a?

    chr()
    rch()
    ord()
    strrev()
    chr(chr())
    chrrev()


  8. If $a is "Hello, world!", is this statement true or false: md5($a) === md5($a)

    True
    False


  9. Which function returns true when magic quotes are turned on?

    get_magic_quotes()
    magic_quotes_get()
    magic_quotes()
    get_magic_quotes_gpc()
    get_quotes()


  10. The functions get_required_files() and get_included_files() are identical, true or false?

    True
    False


  11. If $arr was an array of ten string elements with specific keys, what would array_values(ksort($arr)) do?

    Create a new array of just the values, then sort by the keys
    Create a new array of just the values, then ignore the sort as there are no keys
    Sort the array by key, then return a new array with just the values
    Trigger a warning
    None of the above


  12. What is the return value of array_unique()?

    Boolean
    Integer
    Array
    It varies
    None of the above


Miscellaneous questions

  1. Output buffering compression is...

    High on CPU resources, low on network resources
    Low on CPU resources, high on network resources
    High on CPU resources, high on network resources
    Low on CPU resources, low on network resources


  2. You can exit a PHP code block (that is, use ?> to go back to HTML mode) while in the middle of a class definition: true or false?

    True
    False


  3. Examine this code - on which line is there an error?


    <?php
    class dog {
    public function bark() {
    echo "Woof!";
    }
    };

    $foo = new dog;
    $foo->bark();
    ?>



    Line 2 (class dog)
    Line 3 (public function bark())
    Line 4 (echo "Woof!")
    Line 6 ( }; )
    Line 8 ($foo = new dog)
    Line 9 ($foo->bark())
    There is no error


  4. True or false: to ensure maximum portability for your scripts, you should try to use exceptions.

    True
    False


  5. What directive would you change in your php.ini file to disable assert()?

    assert
    assert.active
    assert.enable
    assert.assert
    assert.options
    None of the above


  6. Which of these statements is true?

    PHP 4 had object orientation, but not extensions
    PHP 4 had extensions, but not object orientation
    PHP 4 had object orientation, but not exceptions
    PHP 4 had exceptions, but not object orientation
    None of the above

Mathematical questions

  1. "10" == 10: true or false?

    True
    False


  2. "10" === 10: true or false?

    True
    False


  3. "10" !== 10: true or false?

    True
    False


  4. 10 === 010: true or false?

    True
    False


  5. 010 >= 10: true or false?

    True
    False


  6. What is the value of this sum: 5 * 6 / 2 + 2 * 3

    0
    3
    4
    19
    21
    24
    29
    51


Database questions

  1. This SQL statement is valid "SELECT ID, Name FROM some_table ORDER BY Name WHERE ID < 100" - true or false?

    True
    False


  2. Joins are fastest when done using which data type:

    INT
    JOIN
    FLOAT
    INDEX
    CHAR
    VARCHAR
    CACHE
    None of the above


  3. SQLite is compiled into PHP 5 by default: true or false?

    True
    False


  4. All five parameters to mysql_connect() are optional, true or false?

    True
    False


  5. What is the best description of a normalised table?

    One where optimal data types are used
    One where data is not repeated
    One where the schema is valid
    One that is properly indexed
    One that has been defragmented


String questions

  1. If $string is set to "Hello, world!", what is $string{4}?

    H
    e
    l
    o
    w
    r
    d


  2. What is the case-insensitive version of the strcmp() function?

    strcmpi()
    stricmp()
    strcasecmp()
    istrcmp()


  3. How many parameters can the trim() function take?

    0
    1
    2
    3
    4+


  4. The parse_str() function...

    Checks a string of PHP code is valid
    Checks a string of PHP code is valid, then executes it
    Searches a string for non-English characters
    Converts the contents of a string into variables


  5. What will this function return: preg_match("[A-Za-z0-9_]*", "This_is_a_test")

    True
    False


  6. What would implode(".", explode(",", $string)) do?

    Replace all full stops (periods) with spaces
    Replace all full stops with commas
    Delete all full stops
    None of the above

PHP MAGIC CONSTANTS

A few "magical" PHP constants :

NameDescription
__LINE__ The current line number of the file.
__FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances.
__FUNCTION__ The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__CLASS__ The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.
__METHOD__ The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).

Interview Questions

1.Difference between span and div?.
2.Javascript validation for Date?.
3.What is Absolute and relative position in Javascript?.
4.What is OOps?.
5.What is Ajax?.and XMLHTTPRequest?How it works?.
6.Why session will work?.
7.What is inheritance?.
8.What is the difference between PHP4 and PHP5?.Mysql4 and 5?.

1. what is the procees that takes place when u type a url on the address bar? eg www.yahoo.com
2. There is a class which has many methods, if there is an error in one of the method which error function will display the error?
3. In which variable is the last occured error stored?
4. difference between CGI PHP and Apache PHP module. (http://blog.dreamhosters.com/kbase/index.cgi?area=2933)
5. difference between require and include.
6. There is file, u include another file in it, which actually does not exist. when u run the file it will show an error. how do u avoid the error being shown. (this should be done in the code not in any configuration setting)
7. difference between sessions and cookies.
8. how to handle error?
9. In how many ways can you submit a form. (not how many methods, how many ways)
10.difference between GET and POST.
11.what is the process that takes place when you upload a file.
12.what is the process that takes place when you download a file.
13.$str=""; what will empty($str) and !isset($str) and is_null($str) return?
14.what is the regular expression to trim the spaces before and after a string?
15.which javascript function to use to get the text of the selected option in a drop down menu.
16.what does the javascript function characterat(am not sure what the name function name is) do.
17.difference between mysql_connect and mysql_pconnect.
18.what cookies should not contain.
19.what is variable variable?

1. what is myql_connect() and mysql_pconnect()?

2. what is the use of session_set_save_handler?

3. write a PHP code 'getimage.php' to tget the binary data from the database, so that the following line of code works

4. write a PHP code to get the user remote IP address.

5. write a PHP code to display a random number between 0 to 100.

6. why is register_global used?

7. In PHP can we use start and end tags?

8. Write a PHP code to produce a thumbnail. how do you resize an image in PHP?

9. how do you POST and information to another URL?
note: do not use form and hidden variables.

10.what is PEAR? Have you ever used PEAR, if yes give example.



1. When do you use classes as compared to functions?

2. Which is the function to display the configuration variables in PHP?

3. What are the four ways we can pass variables from one page to another?

4. What is the difference between asp subroutine and function?

5. What function do you use to open a page in a new window?

6. How can you send a request to the server without leaving the page or relaoding it?

7. Which function do you use to hide or show a div in a web page?

8. Which function will you use to change an image when the mouse moves on a page and then change the image when it comes out of the page?

PHP 6

The PHP world is really excited about the upcoming release of PHP 6.0. Amongst all the uncertainties in any new release, PHP 6.0 seems to be getting rid of three of the earlier troublesome features: register_globals, magic_quotes_gpc and safe_mode. The first was a big security hole, the second messed with the data and made changing environments quite difficult, while the third was usually misread, and provided a false sense of security. There’s also quite a lot of work scheduled to do with Unicode. Read more for some of the changes:

  • The register_globals, safe_mode and various quotes options will be removed.

  • The ereg extension is removed, while the XMLReader, XMLWriter and Fileinfo extensions are added to the core, and by default are on.

  • Another addition I find particularly exciting is that APC (Alternative PHP Cache) will be added to the core, though will be off by default. APC can provide serious performance benefits.

  • All E_STRICT messages will be merged into E_ALL, another positive change that will encourage good programming practice.

  • ASP style <% tags will no longer be supported.

  • A new switch in php.ini will allow you to disable Unicode semantics (by default they will be on).

  • There will also be various string improvements related to Unicode.

  • The microtime() function will return the full floating point number, rather than microseconds unix_timestamp, as at present, probably making the function more readily useful.

  • The {} notation for string indexes will no longer be supported, while the [] version will get added to substr() and array_slice() functionality.

  • FastCGI will always be enabled for the CGI SAPI, and will not allow it to be disabled.
    The ancient HTTP_*_VARS globals will no longer be supported.

  • var will alias public. var was permitted with PHP4 classes, but in PHP 5 this raised a warning. In PHP 6 var will simply be an alias for public, so no warning is necessary.

  • zend.ze1 always tried to retain old PHP4 behaviour, but apparently it “doesn’t work 100%” anyway, so it will be removed totally and throw an E_CORE_ERROR if detected

  • Dynamic functions will no longer be permitted, to be called with static syntax.

  • Both ‘$foo =& new StdClass()’ and ‘function &foo’ will now raise an E_STRICT error.

  • Support for both Freetype 1 and GD 1 support will be removed.Let us await the exiting GD3 soon

  • The FastCGI code will be cleaned up and always enabled for the CGI SAPI, it will not be able to be disabled.

PHP Engine Additions

  • 64 bit integers-A new 64 bit integer will be added (int64). There will be no int32 (it is assumed unless you specify int64)
  • Goto- No ‘goto’ command will be added, but the break keyword will be extended with a static label - so you could do ‘break foo’ and it’ll jump to the label foo: in your code.
  • ifsetor()- It looks like we won’t be seeing this one, which is a shame. But instead the ?: operator will have the ‘middle parameter’ requirement dropped, which means you’d be able to do something like this: “$foo = $_GET[’foo’] ?: 42;” (i.e. if foo is true, $foo will equal 42). This should save some code, but I personally don’t think it is as ‘readable’ as ifsetor would have been.
  • foreach multi-dim arrays-This is a nice change - you’ll be able to foreach through array lists, i.e. “foreach( $a as $k => list($a, $b))”.
  • {} vs []-You can currently use both {} and [] to access string indexes. But the {} notation will raise an E_STRICT in PHP5.1 and will be gone totally in PHP6. Also the [] version will gain substr and array_slice functionality directly - so you could do “[2,]” to access characters 2 to the end, etc. Very handy.

OO changes

  • Static Binding-A new keyword will be created to allow for late static binding - static::static2(), this will perform runtime evaluation of statics.
  • Namespaces-It looks like this one is still undecided - if they do implement namespaces it will be using their style only. My advice? Don’t hold your breath!
  • Type-hinted Return Values-Although they decided against allowing type-hinted properties (becaue it’s “not the PHP way”) they will add support for type-hinted return values, but have yet to decide on a syntax for this. Even so, it will be a nice addition.
  • Calling dynamic functions as static will E_FATAL-At the moment you can call both static and dynamic methods, whether they are static or not. Calling a dynamic function with the static call syntax will raise an E_FATAL.

Additions

  • APC to be in the core distribution-The opcode cache APC will be included in the core distribution of PHP as standard, it will not however be turned on by default (but having it there saves the compilation of yet another thing on your server, and web hosts are more likely to allow it to be enabled)
  • Hardened PHP patch-This patch implements a bunch of extra security checks in PHP. They went over it and the following changes will now take place within PHP: Protection against HTTP Response Splitting will be included. allow_url_fopen will be split into two: allow_url_fopen and allow_url_include. allow_url_fopen will be enabled by default. allow_url_include will be disabled by default.

PHP6 is taking an interesting move in my mind - it’s as if the PHP developers want to now educate developers about the right way to code something, and remove those lingering issues with “Well you SHOULD be doing it this way, but you can still do it the old way”. This will not be the case any longer. Removing totally the likes of register globals, magic quotes, long arrays, {} string indexes and call-time-pass-by-references will force developers to clean up their code.

For more details:

http://php6dev.blogspot.com/#unicode

http://www.corephp.co.uk/archives/19-Prepare-for-PHP-6.html


PHP 5 (New function list)

In PHP 5 there are some new functions. Here is the list of them:

Arrays:

  • array_combine() - Creates an array by using one array for keys and another for its values

  • array_diff_uassoc() - Computes the difference of arrays with additional index check which is performed by a user supplied callback function

  • array_udiff() - Computes the difference of arrays by using a callback function for data comparison

  • array_udiff_assoc() - Computes the difference of arrays with additional index check. The data is compared by using a callback function

  • array_udiff_uassoc() - Computes the difference of arrays with additional index check. The data is compared by using a callback function. The index check is done by a callback function also

  • array_walk_recursive() - Apply a user function recursively to every member of an array

  • array_uintersect_assoc() - Computes the intersection of arrays with additional index check. The data is compared by using a callback function

  • array_uintersect_uassoc() - Computes the intersection of arrays with additional index check. Both the data and the indexes are compared by using a callback functions

  • array_uintersect() - Computes the intersection of arrays. The data is compared by using a callback function