Tag: r

55 votes
19 answers
1.1K views
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?

avatar
Gigi
0 1 0 9
asked 07 September, 2021
52 votes
20 answers
1.3K views
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 containin

avatar
Serina
0 1 0 9
asked 07 September, 2021
56 votes
13 answers
1.1K views
Detecting request type in PHP (GET, POST, PUT or DELETE)

How can I detect which request type was used (GET, POST, PUT or DELETE) in PHP?

avatar
Omar
0 1 0 9
asked 07 September, 2021
52 votes
17 answers
1.5K views
What is the difference between public, private, and protected?

When and why should I use public, private, and protected functions and variables inside a class? What is the d

avatar
Nidia
0 1 0 9
asked 07 September, 2021
65 votes
4 answers
1.8K views
What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

I have tried reading some articles, but I am not very clear on the concepts yet. Would someone like to take a

avatar
Wei
0 1 0 9
asked 07 September, 2021
53 votes
30 answers
2.1K views
Get the first element of an array

I have an array: array( 4 => 'apple', 7 => 'orange', 13 => 'plum' )

avatar
Corey
0 1 0 9
asked 07 September, 2021
55 votes
18 answers
3.1K views
How can I sanitize user input with PHP?

Is there a catchall function somewhere that works well for sanitizing user input for SQL injection and XSS att

avatar
Trudy
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
724 views
Reference - What does this error mean in PHP?

What is this? This is a number of answers about warnings, errors, and notices you might encounter while progra

avatar
Frederick
0 1 0 9
asked 07 September, 2021
66 votes
14 answers
2.5K views
Secure hash and salt for PHP passwords

It is currently said that MD5 is partially unsafe. Taking this into consideration, I'd like to know which

avatar
User demo
0 1 0 9
asked 07 September, 2021
62 votes
30 answers
1.6K views
Enumerations on PHP

I know that PHP doesn't yet have native Enumerations. But I have become accustomed to them from the Java

avatar
Jefferey
0 1 0 9
asked 07 September, 2021
58 votes
14 answers
2.2K views
How to Sort a Multi-dimensional Array by Value

How can I sort this array by the value of the "order" key? Even though the values are currently sequential, th

avatar
Nereida
0 1 0 9
asked 07 September, 2021
58 votes
29 answers
572 views
"Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP

I'm running a PHP script and continue to receive errors like: Notice: Undefined variable: my_variable_na

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
56 votes
28 answers
1.8K views
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 t

avatar
User demo
0 1 0 9
asked 07 September, 2021
52 votes
11 answers
2.1K views
How do you use bcrypt for hashing passwords in PHP?

Every now and then I hear the advice "Use bcrypt for storing passwords in PHP, bcrypt rules". But what is bcr

avatar
Alphonso
0 1 0 9
asked 07 September, 2021
60 votes
26 answers
2K views
Difference between require, include, require_once and include_once?

In PHP: When should I use require vs. include? When should I use require_once vs. include_once?

avatar
Deedee
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
2.2K views
How do I make a redirect in PHP?

Is it possible to redirect a user to a different page through the use of PHP? Say the user goes to www.exampl

avatar
Sachiko
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
2.4K views
startsWith() and endsWith() functions in PHP

How can I write two functions that would take a string and return if it starts with the specified character/st

avatar
User demo
0 1 0 9
asked 07 September, 2021
58 votes
29 answers
603 views
How do I get PHP errors to display?

I have checked my PHP ini file (php.ini) and display_errors is set and also error reporting is E_ALL. I have r

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
69 votes
7 answers
1.9K views
How does PHP 'foreach' actually work?

Let me prefix this by saying that I know what foreach is, does and how to use it. This question concerns how i

avatar
Leonardo
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
2.3K views
How do you parse and process HTML/XML in PHP?

How can one parse HTML/XML and extract information from it?

avatar
Robt
0 1 0 9
asked 07 September, 2021