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 difference between include and require in php?

include will continue executing the script even with errors while require will produce a fatal error and stop the script.

Note: if you put include/require 'grandpa.php' in 'father.php' and then include 'father.php' in 'son.php' and also put include/require 'grandpa.php' in 'son.php' then both require & include will produce errors.

Best thing to add is include_once or require_once in your code as it will only add the file once and will override other include_once or require_once

How can we upload in php?

this is file of index.php or any file that contains uploading area .......

....................................................................................

<body>

<form name="frmFile" method="post" action="fileuploadprocess.php" enctype="multipart/form-data">

<label>Select File</label>

<input type="file" name="flnFile" />

<br />

<input type="submit" value="Upload File" />

</form>

</body>

.....................................................................................................

fileuploadprocess.php that is in form action="fileuploadprocess.php"

<?php

//print_r($_FILES);

//echo(phpinfo());

$sType=$_FILES['flnFile']['type'];

echo($sType);

//echo("<br>");

$arrFileTypes=array("image/jpeg","image/png","image/gif");

$iFileSize=$_FILES['flnFile']['size'];

// For KBs

$iFileSize=$iFileSize/1024;

// For MBs

//$iFileSize=$iFileSize/1024;

echo($iFileSize);

echo("<br>");

//if($sType=="image/jpeg" $sType=="image/png" //$sType=="image/gif")

if($iFileSize<=100)

{

if(in_array($sType,$arrFileTypes))

{

$sDirectory="Uploadfiles/sajid";

if(is_dir($sDirectory))

{

}

else

{

mkdir($sDirectory,0777);

}

$dDateTime=date('mdyhis');

$sTempLocation=$_FILES['flnFile']['tmp_name'];

//$sDesignationLocation="Uploadfiles/".$dDateTime.$_FILES['flnFile']['name'];

$sDesignationLocation=$sDirectory."/".$dDateTime.$_FILES['flnFile']['name'];

//echo($sDesignationLocation);

move_uploaded_file($sTempLocation,$sDesignationLocation);

}

else

{

echo("File type error");

}

}

else

{

echo("File size Error");

}

?>

What is PHP Delimiter?

Delimiter is a special character or a symbol to seperate the string

Is php static or not?

PHP is a dynamic, server-side, web scripting language. It is capable of making connections to a database, and storing information to that database as well as reading queries form the DB. This means that PHP allows for the creation of dynamic web pages that change over time, as opposed to static HTML pages that are rewritten once and do not change without intervention by the page owner.

Who is the best PHP programmer of all time?

Thankfully, there was no stupid competition to determine this outcome. Well it is better to concentrate on Good Coding Practices and various Software Development Models rather then to worry about who is the best and who is the worst

How do you write 55555 4444 333 22 1 in php?

This is one of possible solutions:

for ($i=5; $i>0; $i--)

{

for ($j=$i; $j>0; $j--) {

echo $i;

}

echo " ";

}

?>

How you write log out code in php?

if you're using a session, you can simply use the unset function:

unset($_SESSION);

session_unset();

session_destroy();

good luck !

What is CMS and its Type in PHP?

CMS is a Content Management System, Some types of CMS's that are written in PHP would be WordPress, Drupal, Joomla.

Is this what you were asking?

Is tomcat server use for php?

In normal circumstances only apache server supports php scripts. There can be some tweaking done in tomcat to support php

What is a php session?

A PHP session is a concept where specific variables (and their respective values) are carried throughout a user's viewing of a PHP-driven website.

These sessions can be initialized and continued using the session_start() function. The session values are stored in the $_SESSION global variable. For more information, see the php.net documentation of session functions.

What is a parse error in php?

Parse error in PHP means that your script is invalid - it is not compliant with the programming language specification. After parse error script is no longer executed.

What are the differences between PHP and Pascal?

PHP is:

-a server-side scripting language originally designed for web programming

-younger (first appeared in 1995) and more used than Pascal

-language that interpret it's code (not compile)

Pascal is:

-procedural programming language (PHP 5.3 also implemented Object oriented programming)

-language that compiles it's code into binary file

-published in 1970 by Niklaus Wirth

-used mainly for educational purposes in these days

Source: wikipedia.org

What is the name of php language?

From Wikipedia: PHP originally stood for "Personal Home Page", it is now said to stand for "PHP: Hypertext Preprocessor", a recursive acronym.

https://en.wikipedia.org/wiki/Php

How do you use class and object in php?

I believe the best way is to show you an example:

class Car{

private $gas=0;

private __construct(){

$gas=500; //when you create an object your gas tank is automatically filled with 500 gas for a start

}

public function fill_the_tank($amount){

$gas=$amoung;

}

public function get_gas(){

return $gas;

}

}

$ferrari = new Car;

echo $ferrari->get_gas(); //prints out "500"

$ferrari->get_gas(); //prints out nothing, but also doesn't end up in error

$ferrari->fill_the_tank(100);

echo $ferrari->get_gas() //prints out "600"

What is new in PHP?

PHP is a recursive acronym for "PHP: Hypertext Preprocessor" created by The PHP Group. PHP is a widely used server-side scripting language and the general purpose of PHP is to create dynamic Web Pages. For more information, visit the PHP website.

Why PHP function is called when page is loaded?

There must be a statement in the file which calls the function

What is operator in php?

An operator merges two different values and outputs a new expression based on the inputted values.

What are the syntax and semantics of the include construct?

The PHP syntax and semantics are the format (syntax) and the related meanings (semantics) of the text and symbols in the PHP programming language. They form a set of rules that define how a PHP program can be written and interpreted. PHP is a procedural and object-oriented language (OOL) for coding webpage markup text to be transformed into HTML format on computerized devices. In later releases, PHP generates some code to be run by the Zend Engine, beyond using just HTML markup text. The syntax of PHP changed to include OOL keywords in versions PHP 3 and PHP 5.

What are the four scalar types of PHP?

Four scalar types of PHP

String

String is used for binary data. This can be text, content of an image file etc.

$today = 'hey how are you';

Int

For numeric values, Int is used. Int can contain a positive or a negative number.

$total = 20000000;

$temperature = -14 ;

Float

Float is used for numbers that have a fractional component. Float can also contain positive or negative values.

$length = 145.78;

$growthRate = -5.216;

Sometimes name Double is used for Float values.

Boolean

Boolean is used for values that are either true or false. You would often see Boolean values in conditional statements.

if (($age > 12) && ($age < 20)) {

$teenage = true;

} else {

$teenage = false;

}

//Some content goes here

if ($teenage) {

}

How to display a variable in PHP using echo or print statements?

displaying a variable in php using echo statement?

<?php

$name="ram"; //declaring and defining the variable

echo "$name"; //printing the variable using echo command

?>

How to make constant name case insensitive in PHP?

Generally, constant names are case sensitive in PHP.

But... you can do a trick. If you will be consistent and all constant name will be defines as uppercase, you can access them using a combination of constant() and strtoupper() functions. Look at this example:

?php

define(MY_CONSTANT, "HELLO");

echo constant(strtoupper(my_constant));

echo "
";

echo constant(strtoupper(My_Constant));

echo "
";

echo constant(strtoupper(my_CONSTANT));

?>