1,468,388
questions
5118
votes
24
answers
841k
views
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
What is this?
This is a collection of questions that come up now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
This ...
3082
votes
26
answers
3.8m
views
Deleting an element from an array in PHP
Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element?
I thought that setting it to null would do it, but apparently it does ...
2822
votes
31
answers
2.1m
views
How do I get a YouTube video thumbnail from the YouTube API?
If I have a YouTube video URL, is there any way to use PHP and cURL to get the associated thumbnail from the YouTube API?
2769
votes
27
answers
2.2m
views
How can I prevent SQL injection in PHP?
If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example:
$unsafe_variable = $_POST['user_input'];
...
2728
votes
14
answers
260k
views
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 they work on ...
2653
votes
36
answers
6.8m
views
How do I check if a string contains a specific word?
Consider:
$a = 'How are you?';
if ($a contains 'are')
echo 'true';
Suppose I have the code above, what is the correct way to write the statement if ($a contains 'are')?
2320
votes
32
answers
479k
views
How do you parse and process HTML/XML in PHP?
How can one parse HTML/XML and extract information from it?
2283
votes
7
answers
460k
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 it works under the bonnet, and I don't want any answers along the lines of "this is how you ...
2235
votes
24
answers
842k
views
When should I use 'self' over '$this'?
In PHP 5, what is the difference between using self and $this?
When is each appropriate?
2024
votes
27
answers
3.6m
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 restarted my Apache webserver.
I have even put these lines at the top of my script, and it ...
1725
votes
30
answers
960k
views
How Can I add HTML And CSS Into PDF [closed]
I have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML.
I'm now after a way of converting it to PDF. I have tried:...
1701
votes
37
answers
998k
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/string or ends with it?
For example:
$str = '|apples}';
echo startsWith($str, '|'); //...
1589
votes
34
answers
3.9m
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.example.com/page.php and I want to redirect them to www.example.com/index.php, how would I do so ...
1444
votes
29
answers
710k
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?
1438
votes
39
answers
2.2m
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 through his/her IP address.