Most anwered "php" questions
Use this tag when the question refers to some resource, information, or problem relating exclusively to the PHP programming language. For example: questions about classes, methods, functions, syntax and general use of this language. Do not use this tag if PHP is used circumstantially, but has no relation to the question problem. For example: do not use this tag for questions about HTML formatting, CSS or Javascript code.
Learn more…27,244 questions
Sort by count of
-
11
votes12
answers5446
viewsHow to remove accent in upload with php?
Part of the file is working. The problem is that when I send a file with accent. Example: send a file with the name ação-íaaa.jpg it looks like this on the server ação-Ãaaa.jpg. So I wanted to…
-
27
votes12
answers28737
viewsWhat are the ways to iterate an array in PHP (without foreach)?
Before I am censured by the question, notice beforehand that the purpose of it is simply to level curiosity. I know that the foreach is the most suitable means for this. But I would like to know the…
-
4
votes10
answers29077
viewsScroll through an Array and check if any element is empty
Is there a native PHP function to traverse a array and check if any element of this array is empty null? Observe the code below: if(isset($_POST['btnCriaModelo'])){ $instArray =…
-
20
votes9
answers6629
viewsWhy is using Sessions not a good alternative to authentication?
I see some discussions about using "Sessions" not being scalable, but as I still don’t have enough experience in large projects to realize this, I don’t know how it works.
-
29
votes9
answers30430
viewsHow to debug code in PHP?
For example, in javascript we have the console.log to debug, find out where the bugs are, etc. And in PHP, which ones would be best manners?
-
199
votes9
answers12451
viewsHow to prevent SQL code injection into my PHP code?
I developed a PHP page for internal use of the company I work with and only very few people use it. Through this page it is possible to make some queries, insertions, changes and removals of data…
-
123
votes9
answers13997
viewsHow to create a website without reloading every click on a link?
I’m looking to develop a site that runs all in the same file, but I’m not sure how to look for study material for this. Thus: Normal site->I’m on the Index.php page. When I click on the…
-
9
votes9
answers12142
viewsSearch via ajax during input text ( autocomplete )
I did a search using ajax that when clicking a button triggers a request with the term searched and returns with data that fills a combobox html (select). So far so good. However, I found it…
-
68
votes8
answers67841
viewsHow to export an HTML/PHP page to PDF
How to export an HTML page to a PDF file? Having a standard document where you can change variables within that template and then export that page to a PDF file in A4 format, without spoiling the…
-
36
votes8
answers7830
viewsIs giving a "SELECT" before an "INSERT" a safe way of not having duplicate records?
I have a table with a column codigo. I cannot set as primary key. In a system it receives many notifications before it checks with a SELECT to see if that code already exists in the table. If it…
-
87
votes8
answers75484
viewsError - "Cannot Modify header information - headers already sent"
I have the following code using the function header() of PHP: header("location: painel.php?spv=nav/regMove"); exit; and when it is triggered reports the following error: Cannot Modify header…
-
3
votes8
answers4914
viewsDo not allow saving image of a web page
I don’t want the "save image as.." option to appear when I right-click an image on an HTML page. That is, it will be impossible to save images from the site. How can I do this check?
-
24
votes8
answers64831
viewsHow to check if a checkbox is checked with PHP?
How to check if a checkbox is checked when a form is submitted?
phpasked 11 years, 1 month ago Leandro Costa 2,172 -
10
votes8
answers7818
viewsCheck if variable contains a well formatted PHP email address
The variable receives a value that is supposed to be an email address, but doubts arise: It will be an email address, random text, or anything else? Being an email address, it is well formatted?…
-
12
votes8
answers56968
viewsPHP echo Special character problem ("ç")
I’m developing a website that displays the names of the months with strftime. HTML is already charset=UTF-8. The problem is that in the month name display it appears as in the image below I did a…
-
4
votes8
answers1132
viewsCan you use a variable above when it is declared below?
I have some includes on a PHP page, with inclusion of other pages for user friendly URL, etc. I thought of using Global variables and even constant, but it’s not working. Does anyone know if there…
phpasked 11 years ago Tiago Boeing 830 -
9
votes8
answers6579
viewsCheck user browser in PHP
How do I check if the user is using the Internet Explorer browser, version 10 down, so I can display a message for him to update that before entering my site?
-
6
votes8
answers27292
viewsPHP does not send accents to Mysql database
Good afternoon, you guys! I installed the OCOMON 2.0-RC6 Help-Desk (Call Opening) system and am having the following problem: PHP looks for the accented words of the database and displays them…
-
18
votes8
answers2700
viewsIs it good practice to mix Php and Html?
I see that in python, has the Bottle for example that does the same thing of what I intend to do then... I am new to web practices, student indeed and would like to know if I can use php and html in…
-
15
votes8
answers5012
viewsPrinting a String until a space is found
I receive a String through an input and enter it into the database. When I list, I only want the person’s first name, that is, until the first space is found. Is there any function that does this?…
-
15
votes8
answers1094
viewsIs it recommended to use constants for configuring a PHP project?
It is very common to see constants in a configuration file in a PHP project, but I would like to know if this is really the best practice, because I think if I store the password of a database in a…
-
43
votes7
answers3681
viewsWhat are the implications of not declaring variables in PHP?
In php I can do this without declaring/defining variables: echo($foo); //resolve: vazio, sem nada $foo++; echo($foo); // resolve: 1 Using var_dump() the same gives, respectively NULL and 1. If I use…
-
24
votes7
answers59028
viewsRefactoring function to remove punctuation, spaces and special characters
I have this function already too old to "clean" the contents of a variable: Function function sanitizeString($string) { // matriz de entrada $what = array(…
-
9
votes7
answers30383
viewsHow to dump a Mysql database with PHP?
Currently, to export only the structure of a given database, I use the following: mysqldump -h host -u usuario --no-data --database banco > dump.sql -psenha This generates an SQL file, all…
-
5
votes7
answers7710
viewsHow to send email automatically?
How to send emails automatically using PHP? I have a form that receives several dates and when it was 10 days before the deadline, send a message to several people with the warning. I’ve been told…
-
3
votes7
answers3667
viewsPDO does not connect to Mysql
I’m trying to make a connection to the bank by PDO, but every time I try to make this connection, the message appears: could not find driver I went back to find out and learned that I had to enable…
-
1
votes7
answers175
viewsContact Form
I have this code to check if it is a numeric value and I have tried that the maximum value of digits is 9. I also tried with != or == What I tried: Option 1 //php verif phone…
-
2
votes7
answers367
viewsIs there a problem if I leave a php file containing only HTML code?
I have a php file on my site that serves as a template for a single page of the site, within that file there is only HTML code, there is no php tag <?php ?>, or nothing. It’s like an html…
-
5
votes7
answers762
viewsRandomize results with PHP
I have such a structure (which I created): <div class="banners"> <?php echo do_shortcode("meubanner_1")?> <?php echo do_shortcode("meubanner_2")?> <?php echo…
-
12
votes7
answers552
viewsWhat is the difference between these parameters (array) in these methods?
I see it a lot in methods class Exemplo { public function exemplo1(array $parameters = array()) { } public function exemplo2(array $parameters) { } public function exemplo3($parameters = array()) {…
-
12
votes7
answers1017
viewsIs there any way to know if an array is associative or sequential?
In PHP, a array can be both associative as it can be a list, with sequential numbers. Is there any way to detect this difference in PHP? Example: $a = array('item 1', 'dois' => 'item 2'); //…
-
11
votes7
answers811
viewsHow to write variables in PHP?
I was watching the videos of Robson V.Leite and I realized that at a given moment he retrieves information from the forms to enter into the database in a different way than I use, the only way I…
-
3
votes7
answers1134
viewsSelect a file by name in PHP
Good afternoon, I need help selecting a file by its PHP name. I use the nomenclature pattern starting with the file creation date in the format: 20160111_ALGUMA_COISA and I need my PHP to select…
-
19
votes7
answers22208
viewsIs using MD5 the safest way to encrypt passwords in PHP?
I know there are several methods of encrypting passwords in PHP (md5, sha1, Base64...) although I don’t know much about, what I see most is the use of MD5. Using MD5 to encrypt passwords is the…
-
33
votes7
answers10590
viewsHow do I know if today’s date is Saturday or Sunday (weekend) in PHP?
I want to know the simplest possible way to find out if today’s date is Saturday or Sunday in PHP. What are the possible ways to do this?
-
5
votes7
answers11400
viewsHow to validate phone in php
I’m trying to validate the phone number, both landline and mobile, and I’m trying to do so no matter how the user writes: 11965453789 (11)965453789 (11) 965453789 (11) 96545-3789 It will always save…
-
3
votes7
answers874
viewsExtract Array content for PHP variables
I have a Curl statement that invokes a WS. The answer to this WS is saved via: $reference = var_dump(json_decode($exec, true)); return $reference; Since I have this in one function, in the other…
-
0
votes7
answers4789
viewsForce input with a dot instead of an html comma
In the table the price field has the Decimal data type, where the input is this way: <p><h5><strong>Preço</strong></h5> <input type="text" id="Preco" name="Preco"…
-
51
votes6
answers59467
viewsHow to calculate the difference between two dates?
What is the most practical way to find the time difference between two dates in the default format used by Mysql (YYYY-MM-DD)? Ex: Date 1: 2013-12-11 Date 2: 1994-04-17…
-
6
votes6
answers2089
viewsHow to change the bottom lines of a table alternately? With support for older browsers
My table is created with a PHP loop. I do this by PHP even adding a condition or has some better shape? if ($nomSenha == 'xxxxxxxx') { echo '<table class="pesquisaClientes">'; echo…
-
247
votes6
answers12507
viewsWhy shouldn’t we use mysql_* functions?
A very common question is why should we stop using mysql_* functions? For example mysql_query(), or mysql_connect(). I see that many people use them, or stop using them but do not know the real…
-
9
votes6
answers3652
viewsHow to detect page encoding with PHP?
I wanted to create a function that saved the data in the database encoding correct (my bank is UTF-8) according to the encoding detected. Is there a native PHP function to do this? Is there any…
-
6
votes6
answers1001
viewsError installing Composer in Laravel 4 Project
I’m starting out in the Laravel world and I’m having a problem spinning the composer install in the project. Running the command shows the following error: D:\htdocs\cpi2>composer install Loading…
-
30
votes6
answers10949
viewsHow to measure code performance in PHP?
To measure performance and compare two codes in javascript, I do it like this, in the browser console: // Vamos testar o código 1 console.time('teste1'); for (var i = 0; i++ < 10000;) { $('#table…
-
5
votes6
answers636
viewsHow do you turn the average to red?
How do I make the average result turn red if the value is less than 20? Follows the code: <?php function media($p1,$p2,$p3) { $resultado = ($p1 + $p2 + $p3)/3; return $resultado; }…
-
106
votes6
answers32253
viewsWhat is the best way to create a PHP login system
I’m making a small system, and to access it, the user enters the login and password. What is the best way - safe and simple- to do the login and password system?
-
14
votes6
answers1877
viewsCode refactoring to convert GPS coordinates into DMS format into an array
The user can enter GPS coordinates in two ways, Decimal Degrees or Degrees, Minutes, Seconds: ┌─────────────────────────────────┬─────────────────────┐ │ DMS (Degrees, Minutes, Seconds) │ DD…
-
8
votes6
answers52587
viewsHow do I use a database on an HTML site?
I am interested in making a site that will use a database, many told me they use Mysql to do this, but I have no knowledge about it, installation, use etc. I have knowledge in PHP, HTML, CSS and…
-
8
votes6
answers2251
viewsUpload files (always in different folders)
I wonder if it is possible (and how I could do) I create an upload system where whenever I upload a file, it goes to a different folder (always), and show me (or record) the path it generated. It is…
-
76
votes6
answers20131
viewsDifference between single and double quotes in PHP
What is the difference between single and double quotes in PHP? Yesterday I was working with a string from a google json I used explode('\n', .. to separate a string. When I used the explode in "Mon…