answersLogoWhite

0

PHP Programming

Questions about the PHP programming language; How and when to use it, implementing techniques, debugging and handling errors, and general questions about PHP itself. For questions about software made with PHP, that do not deal with the manipulating, reading, or learning about the actual code, see the Computer Software category.

845 Questions

What is the abbreviation of PHP?

It used to stand for Personal Home Page but today,the first P is dropped and stands for Hypertext Processor

What is the correct way to create a function in php?

function myFunction($parameter1, $parameter2) {

// this function's code goes here

return $returnValue; // the value returned

}

PHP server scripts are surrounded by delimiters?

Yes, PHP server scripts are surrounded by delimiters.

Long starting delimiter:

Short starting delimiter:

Ending delimiter: ?>

Sorting an array in PHP without using sort function?

plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++

What is php in address?

it means that the webpage was programmed in PHP (scripting language), so it's not pure static html, but (at least) parts of it are generated dynamically according to some data (usually from a database) - for example comments that users has added to articles, or such.

What is the meaning of an index in PHP?

are you asking what is the meaning of an index in php as in index.php?

index.php is the default file the web server will load if you don't indicate a file and only a folder.

if your web site was example.com, and you make a subdirectory called /test, then if you wanted a script to run when they type www.example.com/test, then you would make a file called index.php and put it in the subdirectory called test.

same is true with .html files

How does a web server determine whether a requested document includes PHP code?

Web server passes the requested document to PHP interpreter, which validates and processes PHP code in it, then the server reads the response from PHP interpreter and returns the resulting response to client.

For an instance, Apache HTTPD uses instructions such as AddType, to know how to process various documents, basing on their extensions (the following example is common and may require changes depending on Apache HTTPD and PHP configuration):

AddType application/x-httpd-php .php .p8p .txt

This directive instructs Apache HTTPD to let PHP process files which are suffixed with .php, .p8p or .txt, thus files such as index.php, Homepage.p8p and Settings.txt will be processed by PHP.

What is the function of curly braces in PHP?

The curly bracket ({ or }) defines what a function may contained. For example, a correct use of the curly bracket could be:

if(5+5 == 10){
// This is all the data that is contained in the "if" function"
echo '5+5 is 10!";
}
?>

How do you validate empty fields in PHP?

PHP provides a function called empty($var), which tests if $var is "empty." Empty has an odd definition, since the function returns true if the variable loosely equates to False. Although a zero-length string would be considered empty, so would the string "0" (among other irrelevant values).

To accept the value "0" from a field, use strlen($var). It tests the length of any variable, after casting it to a string. If this function truly equals integer zero (compared with triple-equals), the variable must be empty.

What is php mysql?

You are probably referring to running a MySQL query from within a PHP script. This is often done so that the PHP code can perform operations on the data that it gets out from the database. Creating an actual query from php is fairly simple once you have everything else set up, in fact if you know MySQL already you can just use the exact same syntax in PHP.
Here is a link to a tutorial that will show you how to set up everything:

http://www.freewebmasterhelp.com/tutorials/phpmysql/

Is there a limit to nesting elseif statements in PHP?

You can recursively nest as many if / elseif statement groups as you'd like, provided there is enough room to store the PHP file on a computer.

How do you keep the value of a variable between different executions of the same PHP file?

If you want to save a variable to be used in the same script at different executions by the same user, you should try using sessions. Start a session (session_start()) and retrieve the variable in question (for example, $_SESSION['var']). Throughout the script, edit the variable ($_SESSION['var']) and it will automatically be saved for the next execution by the same user.

Alternatively, if you want the value of the variable to be accessed by all users (and allow all users to edit the variable), do as stated above, but before starting the session, define a session name with the session_name() function. All users will refer to the session defined in the session name, thus using the same variable despite the user.

See the related links for further help using sessions.

PHP program to find the minimum number among a list?


// Declare array of numbers.
$list = array( 2, 8, 14, -1, 17, 99 );

// Sort items in ascending order.
sort( $list );

// Output the first (which is least) item.
// Note: if the array is empty, this will issue E_NOTICE.
echo 'The least number is ' . $list[ 0 ];

?>

How do you create a web mail script using PHP?

You can use phpMailer()

Or, you can use mail() PHP function to send emails via PHP script.

Write a PHP program to check whether the string is palindrome or not?

You can do this:

<?php

if ( $word === strrev( $word ) ) {

echo "The word is a palindrome";

} else {

echo "The word is not a palindrome";

}

What is the difference between single quotes and double quotes in PHP?

There's not too much of a difference. Most people prefer using double quotes because of the fact that you can do this: <?php $var2 = "Look at {$var1}!"; ?> which you can't do the {} thing with single quotes. You would have to do <?php $var = 'Look at '.$var1.'!'; ?>

How can you link to a file found in a parent directory without the use of the double-period-slash in PHP?

You can use the double-period-slash (../) to signify a link to a parent directory (for a relative path) or trim the contents of the current script's path (found in the magic constant "__FILE__" and the superglobal array key "$_SERVER['PHP_SELF']") with a function like explode and implode to find the directory above it (for an absolute path).

For the latter, here is an example:





// Get the current script path
$path = $_SERVER['PHP_SELF']; // "/example/path/index.php"
// Divide up the path (into an array) by its forward-slashes
$path = explode('/', $path);
// Remove the last two array keys to get the parent directory
unset($path[count($path)]); // Removes last key
unset($path[count($path) - 1]); // Removes second-to-last key
// Put the path pieces back together with a slash between each piece (to form the path) // Also, add a forward-slash to make it appear as a directory
$path = implode('/', $path) . '/';
// Use the new path as desired!
echo $path; // "/example/"
?>

How do you run PHP in Windows without SQL?

Install Apache server.

The best solution is to install the latest version of WAMP server (Windows Apache MySQL PHP). You can then open the WAMP folder on your hard drive and locate the WWW folder. Inside of the WWW folder you can store your PHP files.

To preview the files open a browser and enter 'http://localhost' to test if the server is working, after testing add the name of a PHP file to the URL, 'http://localhost/myFile.php'.

What is a logical variable in PHP?

Maybe your speaking a variable that contains a ternary operators such as:

$variable = (1 == 1) ? 'value-if-true' : 'value-if-false';

What is the PHP programming language?

PHP is a server-side scripting language mainly for processing a user's data-input and generating dynamic content.

What is the use of equals equals equals operator in PHP?


Consider

$var1== $var2 : This means var1 and var2 must be equal in values
$var1=10;
$var2=10;

so $var1==$var2 is true but if $var2=9; then the above statement will be false

now
$var1===$var2

this will check values and their type i.e both should be integer and value should be 10 only then it will return true.

$var2='dummy';
$var1 === $var2 it will return false.

How do you copy and paste web page content using PHP coding?

file_get_contents($url) helps getting all the content of site.This function have some dependency on php.ini variable.

What is a string variable?

an alphanumeric or string variable is used to represent any non numeric value. it can be represented by one or more letters or digits but it should start with a letter and end with a dollar sign

some examples are a$,r45$ etc....

All variables in PHP start with which symbol?

In PHP, all variables must the preceded by the dollar sign.

Variable name must not contain any space as well.