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.

500 Questions

How do you create a DIV type file using PHP?

User Avatar

Asked by Wiki User

A file with the DIV file extension is a DivX Movie file, it cannot be created with PHP.

PHP is a web programming language for web site building.

How do you insert data to a database using a PHP form?

User Avatar

Asked by Wiki User

You will need a table first, this can be created via your Database - PHPMyAdmin,

  • So, the first step would be to go to your Control Panel for your website, down to PHPMyAdmin and then to the database you are going to be creating the table in
  • Once there, you should see an option at the bottom of your page, not in the left hand menu. 'Create new table on database NAMEOFDATABASE'
  • Name the table, Remember, names of tables shouldn't have spaces, use underscores if you need a space. You will also need to input the amount of fields.
  • Once the fields are correctly named and whatnot, you can start thinking about inputting data into the table.
  • Go to your page editor for a php file you should have created. You should know a little about PHP if you're wanting to input items with PHP, so, let's get to Inputting.

Inputting data in PHP - MySQL

  • Say you've created a registration form, you have all the fields filled out correctly for the person to Register their details, now you need a way for your website to remember that they are now a member right?
  • The table you should have created in your database is a users table, with fields for the Username, Password (which remember, should be set to MD5 in it's function setting), the gender of the Registering user and their Email address. (4 fields altogether then.)
  • Once you have created variables, query checks for the items that need it and MD5'd the passwords, a query is needed to input the details.

e.g

mysql_query("INSERT INTO `users` VALUES('$name','$pass','$gender','$email')") or die("Errored due to:
".mysql_error());

This will Input the values into the table you created with the details of the registering person.

Notice that any form element in an HTML page will automatically be available to your PHP scripts.

Can a database only be stored on a computer?

User Avatar

Asked by Wiki User

No, it can in fact be stored in a file outside of a computer...what boff wants to know that!?

What is the text move function in PHP?

User Avatar

Asked by Wiki User

"Text move" isn't very clear. If you want to assign strings to different variables, use the assignment operator: <?php

$old_var = 'blah';

$new_var = $old_var;

echo $new_var; // Displays "blah"

?>

If you want to work with a certain part of a string, use substr(): <?php

$part_of_string = substr($string, $start, $length);

// $start should be an integer, indicating which character to start obtaining the string at

// $length should be an integer, indicating how many characters you want to obtain.

echo = substr('somesimplestring', 5, 6); // Displays "simple"

?>

What are all the built-in PHP functions?

User Avatar

Asked by Wiki User

See the related links for a shortcut to the entire reference of every function in PHP. The default built-in functions differ from the categories of extensions you choose to install, and the version of PHP you're installing - therefore, it's impossible to give a stable list of built-in functions.

What are some advantages and disadvantages of using PHP?

User Avatar

Asked by Wiki User

PHP is a rather loose language that is fairly upfront. Functions, classes, and variables are easy to manipulate and use. It has very similar syntax in comparison to higher level languages such as C, allowing the branching of more complicated languages (starting with a watered down language like PHP). The PHP engine parses scripts quickly, and has a very elaborate error system, detailing why an error occured, where it started or ended, and what caused it (if applicable). Easy INI settings allow you to surpress these errors when it's time to put your website to professional use (the INI settings can control many other options, at that). PHP has MySQL, Oracle, and many other major database support. Extensions can be added on to further the classes and functions a programmer is capable of performing. You can even write your own scripts and share them with the world with the PHP Extensive Application Repository (or, PEAR for short). However, some people find the PHP language complicated -- or contrary, too loose. Programmers with little experience may find complex source too difficult to understand, and they may never end up understanding it. Programmers with higher levels of experience may find PHP's syntax to be too lose; for example, comparing an integer to string that has an integer in it (two completely different types of variables) would cause errors in higher level languages, stating that the comparison is invalid. PHP allows this sort of syntax, and (in a sense) converts the string into an integer.

What is a preprocessor in PHP?

User Avatar

Asked by Wiki User

As it is, PHP does not have a preprocessor; it is a preprocessor that processes form variables and other environmental variables and prints HTML or general text.

What do you call a CGI expert?

User Avatar

Asked by Wiki User

Most CGI scripts are used for websites, thus CGI experts would be named website programmers. If they use CGI scripting for other purposes, however, another title may be more ideal.

What is the difference between echo and print and printf in PHP?

User Avatar

Asked by Wiki User

The print function is slightly more dynamic than the echo function by returning a value, and the echo function is slightly (very slightly) faster. The printf function inserts dynamic variables/whatever into wherever you want with special delimiters, such as %s, or %d. For example, printf('There is a difference between %s and %s', 'good', 'evil') would return 'There is a difference between good and evil'.

Why PHP developers prefers Laravel?

User Avatar

Asked by Wiki User

Laravel is one of the most preferred PHP frameworks as it has auto-loading to remove maintaining your software, a built-in authentication system you don't have to re-invent for every application, and a lot of other pre-built items that make developing your app easier and faster.

How much should an 18 year old php developer be earning part time in the uk based on a fixed hourly wage with one company not as a freelancer With 5 plus years experience in php and MySQL?

User Avatar

Asked by Phpdev22

You should be earning at least the minimum wage for an 18 year old (which is currently at £4.98/hr) unless you are doing an apprenticeship, in which case they can pay you as little as £2.65/hr.

5+ years with PHP and MySQL experience is pretty impressive for an 18 year old; it would mean developing since you were at least 13!

So let's assume you do 16 hours a week. That's what is usually agreed upon as "part-time" in the UK.

Let's say you do about 39 weeks out of 52 in the year. This is a rough estimate based on being part-time.

That's 16 hours * 39 weeks which is 624 hours in a year you work.

On 18 year old minimum wage that's (624*4.98) = ~£3108/yr.

On <19 year old apprentice minimum wage that's (624*2.65) = ~1654/yr.

Of course you may earn more or less depending on how much you work.

Work it out like so:

x = your total earnings

m = minimum wage for you

h = # hours you work a week

w = # weeks you work in the year

x = (m*(h*w))

JSF Vs PHP?

User Avatar

Asked by Wiki User

JSF, not very well known

JSF, Probably a strict-typed language and therefore difficult for beginners

JSF, Did i mention not very well known?

PHP, Very well known

PHP, Forgiving (also error prone, lets be fair)

PHP, Lots of community support

How do you get difference between two or more arrays in PHP?

User Avatar

Asked by Wiki User

The inherit function `array_dif($arrayOne, $arrayTwo, $arrayThree, ...)` is likely what you're looking for. It compares two or more arrays, and returns an array of values that are unique among the arrays.

Why PHP is more secure?

User Avatar

Asked by Wiki User

All server scripting language speak about it self, why it is secured. Individual perceptions varies on secure ness of a one particular server scripting language.

A programmer's focus is the areas of activities/actions he has to undertake as per the security specification for a particular scripting language to make it secured. It may be PHP,ASP or JSP.

PHP allows you to send emails directly from a script?

User Avatar

Asked by Wiki User

PHP allows you to send emails via your server. This is most commonly done with the mail function, though more efficient alternatives exist like the pear Mail package. Keep in mind that if you have not configured PHP (and your server) to send emails, none of those functions will work.

How can I know what PHP version my site is running on?

User Avatar

Asked by Wiki User

Set up a PHP file and put the following in it.

<?php

phpinfo();

?>

Then run it on the server, it will have all the information you will need including what version you are running.

How do you link an image to a PHP file?

User Avatar

Asked by Wiki User

Wrap the image tag in an anchor link

<a href="mypage.php><img src="mypic.gif" width="10" height="10" /></a>

When i click the php query button its asking to open or save?

User Avatar

Asked by Wiki User

Clearly, this is a case of the server not knowing what to do, so it treats it like any other file.

To run PHP scripts, you will need to configure your server to handle PHP files through the php-cgi or phpexecutable. For Apache, this is accomplished by editing httpd.conf

Add the following to the httpd.conf file:

PHPIniDir ""

LoadModule php5_module ""

AddHandler application/x-httpd-php .php

What is rand function?

User Avatar

Asked by Wiki User

If you are referring to PHP's rand function then.

The rand function is a function that is used to generate a random number between and including two fixed values or two varibles.

An example of this is:

$rand1 = rand(1,9);

echo ($rand1);

?>

This will generate a number between 1 and 9 including 1 and 9

Another exampe of this is:

$value1 = 1;

$value2 = 9;

$rand1 = rand($value1,$value2);

echo ($rand1);

?>

This is also generate a number between 1 and 9 including 1 and 9.

I hope this has helped you.

What is a program flow chart?

User Avatar

Asked by Wiki User

A diagramwhich uses a set of standardsymbols to represent the sequence of operations of a computer program. Such a chart may show, for instance, the steps of a subroutine. Also spelled programflowchart. Also called program flow diagram.

Can you use php to have a user input text and then it show up on an HTML page (as in the php script edits the HTML to add text)?

User Avatar

Asked by MatthewKaskygp3595

Yes. This can be done by posting the data back to the server and outputting the results to the browser.

You would need to create your HTML form which submits the content you wish to manipulate

<form method="post" target="myproject.php">

<input type="text" name="usertext"/>

</form>

On the PHP side (in this case in "myproject.php"), you can read the post data and act accordingly.

<?php

if(array_key_exists('usertext', $_POST)){

$submittedValue = $_POST['usertext'];

}

The key item to note is that the posted data can be accessed as key values in the array $_POST. You can then do whatever you wish with the posted value.

If you want to maintain an ongoing list of items that the user is submitting, you could do it a couple of ways. To maintain it permanently, you'll probably want to open up a database (check out "mysqli" on the the documentation for PHP). If you only want it for that active user session, then you might want to consider another global array called $_SESSION. It is an array that gets stored on the server, retaining data for any user between page loads. The code above could be modified to use it like so:

<?php

session_start();

if(!array_key_exists('submittedValues', $_SESSION)){

$_SESSION['submittedValues'] = array();

}

if(array_key_exists('usertext', $_POST)){

$_SESSION['submittedValues'][] = $_POST['usertext'];

}

Now you can loop through the array $_SESSION['submittedValues'], dealing with every value the user has submitted in their current session.