93 Answered Questions for the topic PHP
Php
05/18/19
How to convert date to timestamp in PHP?
How do I get timestamp from e.g. `22-09-2008`?
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
Remove empty array elements?
Some elements in my array are empty strings based on what the user has submitted. I need to remove those elements. I have this:
foreach($linksArray as $link)
{
if($link == '')
{
...
more
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
PHP array delete by value (not key)?
I have a PHP array as follows:
$messages = [312, 401, 1599, 3, ...];
I want to delete the element containing the value `$del_val` (for example, `$del_val=401`), but I don't know its key. This...
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
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/12/19
Best way to do multiple constructors in PHP?
You can't put two __construct functions with unique argument signatures in a PHP class. I'd like to do this:
class Student
{
protected $id;
protected $name;
// etc.
public...
more
Php
05/12/19
Convert seconds to Hour:Minute:Second?
I need to convert seconds to "Hour:Minute:Second".
For example: "685" converted to "00:11:25"
How can I achieve this?
Php
05/06/19
How to convert an array to object in PHP?
How can i convert an array like this to object?
<pre>
[128] => Array
(
[status] => Figure A.
Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution.
...
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
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/25/19
How can I capture the result of var_dump to a string?
I'd like to capture the output of [`var_dump`](http://us3.php.net/manual/en/function.var-dump.php) to a string.
The PHP docs say;
>As with anything that outputs its result directly to the...
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?
04/04/19
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
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.