|
Previous <
1
2
3
4
5
6
7
8
9
> Next |
| Perl and PHP (INTERVIEW QUESTIONS) |
6 |
|
|
All three allow the script to include another file, be it internal or external depending on if allow_url_fopen is enabled. However, they do have slight differences, which are denoted below.
- include()
The include() function allows you to include a file multiple times within your application and if the file does not exist it will throw a Warning and continue on with your PHP script.
- include_once()
include_once() is like include() except as the name suggests, it will only include the file once during the script execution.
- require()
Like include(), you can request to require a file multiple times, however, if the file does not exist it will throw a Warning that will result in a Fatal Error stopping the PHP script execution.
|
|
|
|
- redir()
This is not a function in PHP, so it will fail with an error.
- header()
This is the correct function, it allows you to write header data to direct the page to a new location. For example:
PHP:
-
header("Location: http://www.search-this.com/");
- location()
This is not a function in PHP, so it will fail with an error.
- redirect()
This is not a function in PHP, so it will fail with an error.
|
|
|
|
- fget()
This is not a function in PHP, so it will fail with an error.
- file_open()
This is not a function in PHP, so it will fail with an error.
- fopen()
This is the correct function, it allows you to open a file for reading and/or writing. In fact, you have a lot of options, check out php.net for more information.
- open_file()
This is not a function in PHP, so it will fail with an error.
|
|
|
|
This is why I tell everyone to, "pick the language for the job!" If you only write code in a single language how will you ever answer this question? The question is quite simple. In Perl, you are required to use the @ sign to start all array variable names, for example, @myArray. In PHP, you just continue to use the $ (dollar sign), for example, $myArray.
Now for hashes in Perl you must start the variable name with the % (percent sign), as in, %myHash. Whereas, in PHP you still use the $ (dollar sign), as in, $myHash.
|
|
|
|
The top two options that are used are sessions and cookies. To access a session, you will need to have session_start() at the top of each page, and then you will use the $_SESSION hash to access and store your session variables. For cookies, you only have to remember one rule. You must use the set_cookie function before any output is started in your PHP script. From then on you can use the $_COOKIE has to access your cookie variables and values.
There are other methods, but they are not as fool proof and most often than not depend on the IP address of the visitor, which is a very dangerous thing to do.
|
|
|
|
This is probably one of my favorite libraries, as it is built into PHP as of version 4.3.0 (I am very happy with myself, I didn't have to look up the version of PHP this was introduced on php.net). This library allows you to manipulate and display images of various extensions. More often than not, it is used to create thumbnail images. An alternative to GD is ImageMagick, however, unlike GD, this does not come built in to PHP and must be installed on the server by an Administrator.
|
|
|
|
Perl in my opinion is great for command line utilities, yes it can be used for the web as well, but its' real power can be really demonstrated through the command line. Likewise, PHP can be used on the command line too, but I personally feel it's more powerful on the web. It has a lot more functions built with the web in mind, whereas, Perl seems to have the console in mind.
|
|
|
|
The === operator is used for functions that can return a Boolean false and that may also return a non-Boolean value which evaluates to false. Such functions would be strpos and strrpos.
I am having a hard time with the second portion, as I am able to come up with scenarios where '==' will be false and '===' would come out true, but it's hard to think of the opposite. So here is the example I came up with:
PHP:
-
if ( strpos("abc", "a") == true)
-
{
-
// this does not get hit, since "a" is in the 0 index position, it returns false.
-
}
-
-
if ( strpos("abc", "a") === true)
-
{
-
// this does get hit as the === ensures this is treated as non-boolean.
-
}
|
|
|
|
Previous <
1
2
3
4
5
6
7
8
9
> Next |
|
|