85 Answered Questions for the topic PHP

Php

05/18/19

What's the best method for sanitizing user input with PHP?

Is there a catchall function somewhere that works well for sanitizing user input for SQL injection and XSS attacks, while still allowing certain types of html tags?
Php

05/17/19

Returning JSON from a PHP Script?

I want to return JSON from a PHP script. Do I just echo the result? Do I have to set the `Content-Type` header?
Php

05/15/19

How to add elements to an empty array in PHP?

If I define an array in PHP such as (I don't define its size): <!-- language: lang-php --> $cart = array(); Do I simply add elements to it using the following? <!-- language:... more
Php

05/15/19

Why shouldn't I use mysql_* functions in PHP?

What are the technical reasons for why one shouldn't use `mysql_*` functions? (e.g. `mysql_query()`, `mysql_connect()` or `mysql_real_escape_string()`)? Why should I use something else even if... more
Php

05/14/19

How to get the client IP address in PHP?

How can I get the client IP address using PHP? I want to keep record of the user who logged into my website through his/her IP address.
Php

05/14/19

NOW() function in PHP?

Is there a PHP function that returns the date & time in the same format as the MySQL function `NOW()`? I know how to do it using `date()`, but I am asking if there is a function only for... more
Php

05/14/19

Get the first element of an array in PHP?

I have an array: `array( 4 => 'apple', 7 => 'orange', 13 => 'plum' )` I would like to get the first element of this array. Expected result: <i>string</i> `apple` One... more

05/14/19

How to perform an action every 5 results?

How can I perform an action within a `for` loop every 5 results? Basically I'm just trying to emulate a table with 5 columns.
Php

05/13/19

How do I check if a directory exists via PHP?

I want to create a directory if it does'nt exist. Is using `is_dir` enough for that purpose? if (!is_dir($dir)) { mkdir($dir);    } Or should I combine `is_dir` with `file_exists`? ... more
Php

05/06/19

How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?

What is the difference between `==` and `===`? - How exactly does the loosely `==` comparison work? - How exactly does the strict `===` comparison work? What would be some useful examples?
Php

05/05/19

PHP equivalent of .NET/Java's toString()?

How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: $myText = $myVar . ''; Like the `ToString()` method in Java... more

05/02/19

Can I develop a mobile app using PHP and Bootstrap?

Php

04/27/19

How to secure database passwords in PHP?

When a PHP application makes a database connection it of course generally needs to pass a login and password. If I'm using a single, minimum-permission login for my application, then the PHP needs... more
Php

04/20/19

Get first key in a (possibly) associative array?

What's the best way to determine the first key in a possibly associative array? My first thought it to just foreach the array and then immediately breaking it, like this: foreach ($an_array as... more
Php

04/18/19

How do I get the current date and time in PHP?

Which PHP function can return the current date/time?

How do I easily highlight the syntax of PHP code in Word?

How do I easily write and syntax-highlighted PHP code (or any others programming language) in a Word 2009 document?
Php

04/04/19

Why doesn't this code simply print letters A to Z?

a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc bd be bf bg bh bi bj bk bl bm bn bo bp bq br bs bt bu bv... more
Php

04/03/19

How to pass variables and data from PHP to JavaScript?

I have a variable in PHP, and I need its value in my JavaScript code. How can I get my variable from PHP to JavaScript? I have code that looks like this: getValue(); // makes an api and db... more
Php Sql Mysql

03/25/19

Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax t

<?phpsession_start();require('connect.php');if(isset($_POST['submit'])){$id = $_POST['id'];$username = $_POST['username'];$name = $_POST['name'];$email = $_POST['email'];$password =... more

Should a CMS be used for a photographer portfolio web site?

My friend photographer asked me to develop a portfolio web site, and I'm wondering if a content management system (CMS) should be used for this purpose? The website contains a minimum of dynamic... more

03/19/19

Showing Featured Item From the Database?

I have database table as below. id, bungalow_name, type, address, featured A bungalow can be featured in the home page. If a bungalow is featured, `featured` column has the value `1`. I have 50... more
Php

03/18/19

How do I convert a string to a number in PHP?

I want to convert these types of values, `'3'`, `'2.34'`, `'0.234343'`, etc. to a number. In JavaScript we can use `Number()`, but is there any similar method available in PHP? Input ... more
Php

03/18/19

Formatting a number with leading zeros in PHP?

I have a variable which contains the value `1234567`. I would like it to contain exactly 8 digits, i.e. `01234567`. Is there a PHP function for that?
Php

03/18/19

PHP mail function doesn't complete sending of e-mail?

I've tried creating a simple mail form. The form itself is on my `index.html` page, but submits to a separate "thank you for your submission" page, `thankyou.php`, where the above php code is... more
Php

03/18/19

How to find the last day of the month from date?

How can I get the last day of the month in PHP? Given: $a_date = "2009-11-23" I want 2009-11-30; and given $a_date = "2009-12-23" I want 2009-12-31.

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.