Most voted "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
-
27
votes4
answers16118
viewsWhat is the difference between Static and self in PHP?
What’s the difference between static and self? Exemplify situations that justify your different uses. What does this have to do with late Static Binding?
-
27
votes6
answers11785
viewsIs there an advantage to using filter_input instead of isset?
I’ve always been used to using the isset to check if an external variable is filled and if you are using it. Example: if(isset($_GET['pag'])) $pag = $_GET['pag']; Now I installed the Netbeans and…
-
27
votes5
answers31170
viewsWhat are Try/Catch Blocks for and when should they be used?
I’ve been looking for some explanations on the subject, but I couldn’t find one that was simple and straightforward. My question is : What Try/Catch Blocks are for and when they should be used?…
-
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…
-
26
votes4
answers2688
viewsHow to package and distribute a web system?
I need a certain Web system - including the PHP server itself, as well as Mysql - to be "packaged" in an executable file, thus allowing the layman to use it in a kind of browser of his own. What…
-
26
votes2
answers5355
viewsGet colors from the image
There is a possibility (with plugins or not) to catch the [main] colors or the predominant colors, similar to Adobe Kuler, image? Example I have this image: And I wanted to take her main colors,…
-
26
votes2
answers3291
viewsCrop image with Javascript
I need to upload a photo and then put it in a modal for the user to make a proportional cutout 4/3 a short web search found this jQuery plugin jCrop. He seems to provide me with the coordinates to…
-
26
votes2
answers28661
viewsIs there an API to send a message via Whatsapp using PHP?
Is there an API to send a message to Whatsapp from a person using PHP?
-
26
votes6
answers12868
viewsWhat’s the difference between Isis and elseif?
I wanted to know the difference between else and elseif in PHP, and when should I use one or the other.
-
26
votes2
answers5412
viewsWhat is Lazy Loading and Eager Loading?
What is Lazy Loading and Eager Loading? I saw these terms in a documentation, but I did not understand it very well, so my doubt is what these terms mean and I would like, if possible, to restrict…
php cakephp language-independent advance-charge lazy-loadasked 9 years, 8 months ago Ricardo 14,521 -
26
votes6
answers10518
viewsDifference between php <?php tags and <?=
Well I’m learning Laravel and I was left with a doubt following some tutorials. At certain moments within the view the tag is used : <?php foreach($produtos as $p): ?> and when will I get the…
-
25
votes3
answers6810
viewsDifference between PATH_SEPARATOR and DIRECTORY_SEPARATOR
The documentation on this is rather vague, the little that exists does not clearly clarify the difference between the use and purpose of the following two PHP constants: PATH_SEPARATOR and…
-
25
votes3
answers9925
viewsDifference between './', '.. /' and '/'
In some codes I work, sometimes there is no global variable that points to the root of the project, such as: $RAIZ='PATH/EXAMPLE/'; So they often use: src='./somePath'; src='../somePath';…
-
25
votes3
answers22400
viewsWhat is the difference between bindParam and bindValue?
What’s the difference between Pdostatement::bindParam() and Pdostatement::bindValue()?…
-
25
votes4
answers1768
viewsWhat is the difference between ; and & in a URL?
I was watching a website to add in a C#application, I noticed a link similar to this: www.site.com.br/index.php?post=yes;user=1521; The parameters are separated by ;(semicolon). I accessed the same…
-
25
votes1
answer8303
viewsHow to sign a PDF digitally?
I am developing a PHP system with the Laravel 5.1 framework that will generate some technical reports, and the client wants these reports to be digitally signed, IE, que conste la no PDF generated…
-
25
votes2
answers1684
viewsHow does namespaces work in PHP?
The namespaces were implemented from PHP version 5.3.0 as a form of "encapsulating items". I never really understood his real concept, and I always get confused with autoload of classes. Could…
php characteristic-language namespace php-autoloadasked 9 years, 3 months ago Gabriel Rodrigues 15,969 -
25
votes1
answer19287
viewsHow does PHP-FPM work?
Guys, I have a question related to the concept of PHP-FPM. From what I understand from the documentation, it is a module of PHP that manages requests to the server to avoid high loads, or am I…
-
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(…
-
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 -
24
votes2
answers24948
viewsWhat is the difference between Switch, Case and If, Else?
I’d like to know the difference between switch .. case and if .. else. Which offers a better "performance"?
-
24
votes2
answers32776
viewsURL friendly, how to make it work with HTACCESS
I created some rules in my file .htaccess to format the display of URL, but I’m having difficulty passing the parameter to the page that shows the products and show the URL Friendly formatted, the…
-
23
votes3
answers59486
viewsHow to compare dates in PHP?
I would like to know which function I use to compare two dates and return to larger. I have a form for HR registration in which the user will register their professional experiences and the date of…
-
23
votes2
answers268
viewsNull attributes on an object is Bad?
I have an object that has 7 attributes: 2 attributes are always with some value assigned. 3 values are always set if a filter query is required (3 attributes are filters). The last 2 attributes are…
-
23
votes1
answer46824
viewsWhat’s different from Xampp, Wamp, Easyphp, Zwamp and PHP?
What a difference from Xampp, Wamp, Easyphp, Zwamp and PHP? They are all servers? Are all official PHP?
-
23
votes2
answers418
viewsIs it bad practice to use empty interfaces?
I have heard comments that it would be a good idea, when a future implementation can take place. Also heard that it is a bad practice. I know that in PHP, for example, there is an interface called…
-
23
votes2
answers905
viewsHow does PHP foreach work?
To clarify, this question is not about when the foreach is used or differs from it to other loops of repetition, but about the functioning of foreach in itself. In the documentation, little is said…
-
22
votes3
answers12113
viewsCheck if a table exists in the database
How to check if a table exists in the database before trying to use it? <?php // define a tabela $table = 'banana'; // verificar se tabela "banana" existe aqui // $tableExists = ?? // executa…
-
22
votes4
answers2442
viewsIn PHP how to calculate a random number?
How to calculate a random integer between 1 and 2000 using PHP, to make a draw? function random() { // codigo }
-
22
votes3
answers63728
viewsAdd days to a date
I need to add 2 more days on a date coming from a variable. I’m doing it this way but it’s not working. $data = '17/11/2014'; echo date($data, strtotime("+2 days"));…
-
22
votes3
answers51011
viewsHow to send email from localhost using PHP’s mail function?
I want to send emails from localhost. <html> <head> <meta charset="utf-8"> </head> <body> <h1> Olá mundo!</h1> <?php $enviar = mail(…
-
22
votes4
answers68381
viewsScript returning Parse error: syntax error, Unexpected end of file
When including this method to a PHP code <?php function meuMetodo($a, $b) { $c = $a + $b; if ($c > 1) { return TRUE; } else { return $c; } ?> This error occurs: Parse error: syntax error,…
phpasked 10 years, 1 month ago Guilherme Nascimento 98,651 -
21
votes2
answers14288
viewsHow to disable a text field for editing using jQuery/Javascript?
Let’s say I have a form with fields 1 to 7. Something like: field-1 field-2 field-3 field-4 field-5 field-6 field-7 All these fields are in one form. With Laravel, sometimes I experienced situations…
-
21
votes1
answer329
viewsHow to implement memoization in a PHP function?
I saw it today in a reply the following code: function fibonacci($n) { $a = 0; $b = 1; $c = 1; for ($i = 1; $i < $n ; $i++) { $c = $a + $b; $a = $b; $b = $c; } return $c; } echo fibonacci(100)…
-
21
votes6
answers1578
viewsIs it good practice to use constructors (or magic methods) in interfaces?
Well, I usually come using interfaces to define how some methods will be used. But to be honest, I’ve never seen anyone using interfaces to define contracts for a construtor. In a specific case I…
-
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.
-
20
votes2
answers11900
viewsHow to make a JOIN between two tables of two different databases?
I have the personal data (login, password, name, etc.) of the users on a different server than I will use in a new project. I would like to know how I can cross-reference information between two…
-
20
votes3
answers4785
viewsPHP and Mysql, how are thousands of connections processed at the same time?
Using PHP and Mysql as an example, let’s assume that there are 1000 connections (clients) accessing the site and using functions that open connection to Mysql and make queries. How PHP and Mysql…
-
20
votes4
answers6072
viewsHow to write code as an example, without running?
I’m doing the translation of a book to an HTML page, ai in the book has the codes, but how do I make my HTML display my code, HTML, PHP and Javascript, without running them?
-
20
votes1
answer432
viewsWhat is the ~ (til) operator for in PHP?
What is the operator for ~ (til) in PHP? I’ve seen things like: echo ~PHP_INT_MAX Until then I thought it was to "reverse" a number to negative, or something like that, but with the tests I saw that…
-
20
votes2
answers766
viewsHow to humanize a date in PHP
How to humanize a date in PHP? For example, from that date 2015-08-20, I want the function to return to me Há uma semana, because it’s strange to read something like foi publicado há 754 dias or…
-
20
votes4
answers19928
viewsstrtoupper() with accents
The function strtoupper() PHP is not turning the accented letters into uppercase, see the example: echo strtoupper("virá"); // retorna VIRá Do you have any native function that solves this problem?…
-
20
votes6
answers3379
viewsHow to find out if the year is leap in PHP?
How do I know if the current year is a leap year in PHP?
-
20
votes5
answers2497
viewsWhat is the purpose of the "Spaceship Operator" <=> of PHP7?
I was just taking a look at the New Features of PHP 7 and I came across an operator, who I had never seen in any programming language. The PHP Handbook demonized him of Spaceship Operator. I’ll…
-
20
votes3
answers3434
viewsWhat does "sanitize" data mean?
I’m making a form, and I’m doing the validation part... I see the term a lot sanitize or sanitizar, what it means? I’ve even seen some functions in the php that carry this term in their parameters.…
-
20
votes4
answers4351
viewsHow and why use MVC in PHP?
I always made websites and systems without problem using structured PHP, came the curiosity if it is possible to make a system in OOP completely and if it is more advantageous. Searching I found the…
-
20
votes3
answers376
viewsNSA Challenge - "Thirteen men and a shipment"
Browsing the internet looking for challenges (to be solved with programming), I found the "Thirteen men and a shipment", where said it is part of the random challenges of the NSA (link). The…
-
20
votes1
answer1027
viewsGalton’s Board - Central Limit Theorem
The reason for the question is study/learning. Know/apply programming techniques and concepts, transforming something "material" into "application". I received a video on Whatsapp, where mixed…
-
20
votes2
answers264
viewsHow does PHP handle type declaration?
Still in PHP 5 it was already possible to make the declaration of types in arguments of function. Type statements Type declarations allow functions to require parameters to be of certain types when…
-
19
votes3
answers32219
viewsFetch last 7 days data from current date
I’m making a BD query, and I want to receive results from the last 7 days from the current date. For that, I have a field data of type DATA (yyyy-mm-dd) in table. I am doing the query in php, in…