Posts by Wallace Maxters • 102,340 points
1,984 posts
-
2
votes1
answer300
viewsA: What is the Traversable interface for in PHP?
To explain this, I will have to talk about three interfaces: Iterator, Iteratoraggregate and the Traversable. Let’s explain in parts: According to the Manual for PHP (translated by me, more or less…
-
2
votes4
answers1750
viewsA: How to create a list of dates of the year in php, skipping the weekends?
I have a solution too, and it’s almost similar to @rray’s response, but with some variations and explanations regarding Iterators used. Come on: // Defini a data inicial como 01/01 do ano atual…
-
7
votes4
answers1750
viewsQ: How to create a list of dates of the year in php, skipping the weekends?
I need to create a list of dates in PHP, where I will list all dates, from the first day of the year, until the last. However, in this list, dates referring to the weekend (Saturday and Sunday) must…
-
8
votes2
answers209
viewsA: Is there a package management system on the Moon?
In addition to @Maniero’s reply The LuaRocks allows you to create and install Lua modules as independent packages. For those who use Linux operating system, the installation is very simple. apt-get…
luaanswered Wallace Maxters 102,340 -
2
votes2
answers492
viewsA: PHP security failure
Theoretically, from the code posted in the url, they tried to make an attack where, using a possible enabling allow_url_include in php.ini, they tried to run a command via url (I think in some…
-
9
votes2
answers209
viewsQ: Is there a package management system on the Moon?
Many languages have package management system. This greatly facilitates the life of the programmer, making development more agile. For example, in the Python we have the pip and the easy_install, in…
luaasked Wallace Maxters 102,340 -
0
votes1
answer59
viewsA: Symfony2 - Security/Custom User Class
There is no problem in having the name of the desired properties, as long as you return correctly what the interface implemented requires. An interface in PHP "force" that the class has the methods…
-
3
votes1
answer978
viewsA: Pass a view JSON to the route
It’s not the best way, or I can still say it’s wrong. You are concatenating a javascript object with a string (in the url). var json = { "numeroMesa": numeroMesa, "itens": itens };…
-
14
votes1
answer300
viewsQ: What are the improvements that the Spread Operator implementation will bring to javascript?
I’m taking a look at the new Eatures of the EcmaScript6 and saw that the Spread Operator. He looks very similar to variadic function PHP (which also uses Spread Operator). Here’s an example of what…
-
0
votes3
answers395
viewsQ: How to specify directory where Bower will place dependencies?
I installed here in my machine the bower globally. npm install -g bower So when I use the remote bower install jquery, he installs it in the folder called bower_components. Is there any way to make…
bowerasked Wallace Maxters 102,340 -
1
votes1
answer185
viewsA: foreach running in a 10 minute interval
500 to 500 you want to run each 2 minutos? Use the function array_chunk to share your array 500 to 500. And apply a foreach with a Sleep at each iteration with this subdivision of its array.…
-
19
votes1
answer10250
viewsQ: What is REPLACE INTO for in MYSQL?
What is the purpose of the command REPLACE INTO in MYSQL? Example: REPLACE INTO tabela(col1, col2) values(value1, value2) WHERE id = 1
mysqlasked Wallace Maxters 102,340 -
6
votes2
answers707
viewsA: How to limit display of records to 30 days from today’s date
The solution I would apply is to check whether the bank date is greater than or equal to -30 days from today’s date. Thus: $data = (new DateTime('-30 days'))->format('Y-m-d H:i:s'); $sql =…
-
1
votes1
answer84
viewsA: Prevent or remedy it?
The question can be interpreted as based on opinions, because, as a friend of mine would say: Everything depends. Do you necessarily need the data to exist? Then it is necessary that they are…
-
3
votes2
answers435
viewsA: PHP logout with Codeigniter
There is a time that I don’t work with Codeigniter, but the solution below will work with any other framework (or even in pure PHP). Considering that you have destroyed the session, to ensure that…
-
17
votes1
answer1667
viewsQ: What is the goal of implementing a magic __invoke method in a class?
I know what the method is for __invoke. It is for a class to execute an action if called as a function. Even, it is present in the special php class called Closure, which is instantiated when we…
phpasked Wallace Maxters 102,340 -
13
votes3
answers1303
viewsQ: What is a git submodule for?
One day I went to clone a library in the github and there was an instruction to use the command git submodule update. I’ve been working with the git and until then had no knowledge of this command.…
gitasked Wallace Maxters 102,340 -
9
votes4
answers1308
viewsQ: What is the purpose of an empty parenthesis "()" in a regular expression?
Searching in Stackoverlow English about regular expressions, I came across a certain expression where it presents in the same an empty group (an expression in empty parentheses). Thus:…
regexasked Wallace Maxters 102,340 -
8
votes5
answers631
viewsQ: str_split does not work well in string containing UTF-8?
I want to iterate a string with foreach. For this, I learned that I must use the function str_split, that separates each character from the string to a array. However, this operation does not work…
-
5
votes1
answer319
viewsQ: Why does the PSR2 standard require us to use 4 (four) spaces instead of tab?
According to one of the items specified by the standard PSR2 (to which most PHP libraries), we have: Codes MUST use 4 spaces for indentation, not tabs. I know the pattern exists, but I’d like to…
-
2
votes1
answer208
viewsA: How to load files, folders and subfolders using php
Through the attribute webkitdirectory or directory (in the same way that you use multiple), you can add this functionality to your input file. Exemplifying: <input type="file" webkitdirectory…
-
4
votes2
answers6097
viewsA: How do I put Hover in an image?
It is not necessary to use exactly one image (I’m talking about the tag img). You can use a div with background-image. Inside that div you’ll put another div, with opacity:0. When pass the mouse…
css3answered Wallace Maxters 102,340 -
1
votes1
answer501
viewsA: By removing the index.php prefix in wampserver windows, is it possible?
Yes, it is possible. You need to change the .htaccess and check whether the mod_rewrite is active. In htaccess you put like this: RewriteEngine On RewriteRule ^(.*)$ index.php/$1 Remembering that,…
-
15
votes1
answer1975
viewsQ: What good is a Fatherland ( b) in a regular expression?
A long time ago, I took a look at the use of Boundary, studying about regular expressions in PHP (PCRE Patterns). I came across the \b (which is called Boundary). What is the use of it in a regular…
regexasked Wallace Maxters 102,340 -
2
votes1
answer85
viewsA: Efficient execution of PHP PDO queries
The way you do it there is no difference as to the performance. The results will be the same. The question of whether or not to assign the variable to foreach will make a difference in the following…
-
0
votes1
answer81
viewsA: How do I know the current connection the system is using in Cakephp 3.0?
That answer was taken from SOEN . You can do it like this: $this->{$modelName}->connection()->config();…
-
14
votes2
answers625
viewsQ: Is it really necessary to use mutator and access (Setter and getter) methods in PHP? What about performance?
I’ve been noticing that most other libraries use the methods setters and getters (hereinafter referred to as mutator and accessor), to change the property of some classes. For example: class User {…
-
3
votes1
answer96
viewsQ: The end of a capture in a regular expression
I don’t know which title could be better than that, because I don’t really understand technical terms related to regular expression. But let me describe my problem. I have a code, where I get a…
-
21
votes2
answers6309
viewsQ: How to remove a CSS attribute with jQuery?
In jQuery, it is possible to add an attribute to an element through the function attr. You can also remove an attribute through the function removeAttr. And when I define an attribute of css through…
jqueryasked Wallace Maxters 102,340 -
14
votes3
answers1114
viewsA: Working with lists without using Array() in PHP
Yes, there are some standard classes (from the SPL-Standard PHP Library) in PHP that do this job very well. Usually these classes implement the interfaces ArrayAccess, Iterator or IteratorAggregate.…
-
12
votes2
answers610
viewsQ: Is it bad to use the standard PHP session engine?
What I understand is that many frameworks, like Codeigniter and Laravel 3 and 4 use their own session storage engine. They don’t use the standard PHP engine (Variable $_SESSION and session_start,…
-
3
votes2
answers77
viewsA: Does not redirect in Firefox
Your code seems to have some errors, or rather it wouldn’t be the best way to do it. setInterval will generate a repeat at a given interval. If you want to delay the redirect, use setTimeout, that…
-
2
votes2
answers4557
viewsA: How to compare two arrays and return the difference between them?
If you just want to return one array single, both with users who is with array as in another, it is easier for you to join the two arrays and then return the single values of the sum two.…
-
1
votes4
answers2091
viewsA: How to send variables via ajax/php
I am always in favor of practices that facilitate the visualization of the code. Then, in this case considering the variables "loose" $ovo and $colar, I would use the function compact to turn a list…
-
6
votes2
answers5121
viewsA: How to keep the session after browser close?
In PHP the directive responsible for session time on php.ini is the sesion.cookie_lifetime. A session uses a file, in the php temporary folder, whose name is a hash. In turn every session uses a…
phpanswered Wallace Maxters 102,340 -
3
votes3
answers315
viewsA: Syntaxerror: unterminated string literal JAVASCRIPT
Buddy, I would do it this way to facilitate the visualization of things in your code. printf('fnc_eglise_ajaxGet("ajax/deletaPessoaVinculo.php?%s");', http_build_query(array( 'd' =>…
-
4
votes2
answers582
viewsA: Print two arrays side by side
I would do with a array_map to generate an array "side by side" and then iterate it with foreach. $array1 = [1, 2, 3]; $array2 = [1, 2, 3, 4]; foreach (array_map(null, $array1, $array2) as $key…
phpanswered Wallace Maxters 102,340 -
2
votes1
answer260
viewsA: Pagination hasMany Laravel 5.1
Instead of directly calling the relationship, you can use the relaciomanento method to be able to call the paginate. $cliente = Cliente::findOrFail($id_cliente); $usuarios =…
-
18
votes1
answer10056
viewsA: Upload images with Crop and resize, jQuery and PHP
Come on, come on. It may be a long explanation. Points to be clarified When you use a Crop via Javascript/jQuery, you are not cutting the image itself. You are just saving the coordinates, relative…
-
11
votes2
answers2040
viewsA: How to store the value of the indexes of this JSON in variable?
Solution Do so: $dados = json_decode('[{"id":81,"username":"usuarioteste23"}]', true); $id = $dados[0]['id']; $username = $dados[0]['username']; Explanation What its function returns is a php…
-
1
votes1
answer261
viewsA: Problems with php printing with file_get_contents(); - mpdf
file_get_contents does not interpret PHP code. It just reads a file as a string and stores it in memory. So that the php code is interpreted and you can see what was printed by echo should use the…
-
0
votes4
answers114
viewsA: How to make a query that returns the last record of each day?
I believe you need to format to date and then group. SELECT * FROM tabela GROUP BY DATE(data) ORDER BY data DESC
mysqlanswered Wallace Maxters 102,340 -
20
votes6
answers3379
viewsQ: How to find out if the year is leap in PHP?
How do I know if the current year is a leap year in PHP?
-
15
votes6
answers3379
viewsA: How to find out if the year is leap in PHP?
To do such an operation you can use two ways, but the two lead to the same method: Check whether February ends with day 29. Strtotime and date (date('d', strtotime('last day of february this year'))…
-
4
votes2
answers1573
viewsA: Show real-time loop result
You’re probably talking about ob_implicit_flush. Yes, it is possible to display an output in php even while running a loop, without waiting for that loop to be finished. That is, the data is printed…
-
1
votes2
answers2985
viewsA: dompdf php to pdf
Yes, there is. The way I know to "get the final html" is to give a include and capture it in output buffer. Example: ob_start(); include 'seu_html_gigante.php'; $dompdf->loadHtml(ob_get_clean());…
-
3
votes3
answers7306
viewsQ: Check if a process is not running and then run it
I need to run a certain command via terminal. However, this command should only be run if the terminal process is not running. If it is running, there is no need to do any other operation. How to do…
-
1
votes1
answer172
viewsA: Imgselect: Mediastream stop is not a Function
I managed to solve the problem on my own. I am not in favor of changing source code of anything, but in that case I changed the code of the Imgselect that had this excerpt: if (n) n.stop(); For that…
javascriptanswered Wallace Maxters 102,340 -
3
votes1
answer83
viewsQ: How to automatically include a file, which is not a class, in Composer?
In Composer, usually when we configure autoload for files that contain classes, I usually do so: "autoload" : { "psr-4" : { "WallaceMaxters\\Timer\\" : 'src/timer'} } Composer will automatically…
-
1
votes1
answer147
viewsQ: Why doesn’t kwargs accept a keyword? [keyword can’t be an Expression]
In python there is the kwargs, that makes things so much easier when I need to name parameters. define the attributes of an element that I will create with this function I have a function where the…
pythonasked Wallace Maxters 102,340