Posts by Wallace Maxters • 102,340 points
1,984 posts
-
2
votes2
answers70
viewsA: How to insert the connection inside the functions without repeating the instructions?
The idea of @rray to pass PDO as argument really is excellent. Only as a complement, it is possible to induce the type of the parameter so that the PDO. Example: function excluir(\PDO $pdo, $id) {…
-
4
votes2
answers1090
viewsQ: Is there any way to debug PHP via browser console?
Is there any way to debug PHP via browser console? I sometimes want to debug a value on the system in production, but I wouldn’t want the user to notice. Then I got the idea to use the browser…
-
8
votes2
answers1090
viewsA: Is there any way to debug PHP via browser console?
I even asked the question and answered, because I’ve never seen anyone with such curiosity. There is a way, and I created it in this gist The code is very simple. It is possible to pass infinite…
-
0
votes2
answers685
viewsA: Error Call to a Member Function Row() on a non-object Codeigniter
This happens because the function get_byid does not return a objeto at some point, and yes a FALSE. Probably this generates an error. Instead, if no result is returned you should launch a Exception…
-
5
votes5
answers1552
viewsA: Restriction of words in comments
Regular expression can also be another way out of this. I did something to detect sites with inappropriate urls not long ago, that way: #blacklist.php return array( '(.*)\.(xxx)', '4tube\.com',…
phpanswered Wallace Maxters 102,340 -
5
votes1
answer6989
viewsA: mb_convert_encoding vs utf8_encode()
Simply and quickly: mb_convert_encoding converts an X encoding to a Y encoding. utf8_encode encodes the string ISO-8859-1 for UTF-8. Note then that the difference between the two is very wide.…
-
2
votes1
answer207
viewsA: Laravel 4.2 - 405 Method Not Allowed
To access the method PUT, it would be necessary that the request made to that url was also of the type PUT. This request cannot be made via form, only via ajax. Forms The method not allowed is being…
-
5
votes1
answer2641
viewsA: What makes it explode() better than split() in php?
Split is a function of older versions of PHP, which did something similar to explode, differing in the use of regular expressions. I don’t remember the reference now, but that function was six times…
phpanswered Wallace Maxters 102,340 -
2
votes4
answers814
viewsA: Repeat alphabet similar to excel columns
You can do it like this: for ($a = 'a'; $a != 'aaa'; $a++) { $colunas[] = $a; } This will generate a array with a sequence of a until zz. If you need to set a limit, you can do so: function…
-
9
votes6
answers11785
viewsA: Is there an advantage to using filter_input instead of isset?
One thing I don’t think anyone has commented on, but I think it’s important to point out is that filter_input has a big difference from the isset. The isset will check whether a particular one is…
phpanswered Wallace Maxters 102,340 -
1
votes2
answers107
viewsA: Problems when using Heredocs
Your HEREDOC has a space after the <<<. Also another problem that occurs is to find that after the <<<EOT we can use spaces. Generally, after the declaration <<<EOT comes…
phpanswered Wallace Maxters 102,340 -
0
votes3
answers1647
viewsA: Take the first and last date of an array
If the question is sorting the data list, I would use the function usort. She orders a array according to a comparison made by a callback. Then see what beauty (a date has been modified to check…
-
2
votes4
answers1739
viewsA: Expire php link
For sure, you will have to save this information in the database. I usually do the following: In the table referring to the user, when it asks for password recovery, record in a table field a…
-
3
votes2
answers1685
viewsA: How to format all elements of a list in Python?
Only as a complement to the @Ciganomorrizonmender: This operation, in Python, is called List Comprehensions. It can be used to build the lists in a very simple way. If the goal is only to create the…
-
2
votes1
answer120
viewsA: Doubt with Routes and Controllers Laravel 4
Amanda, it turns out that what brings back the blank page in your code is the View::make that’s inside the if. If it does not meet the condition, as it is not returned, then your code will return a…
-
3
votes2
answers72
viewsQ: Why are non-https origins considered unsafe by browsers?
I asked a question now asking about a feature that has become obsolete in a particular browser, why is it not a source with ssl. I fully understand that the https improves the security of the site,…
sslasked Wallace Maxters 102,340 -
4
votes1
answer768
viewsQ: getUserMedia has now been discontinued on non https connections?
This morning I updated my Google Chrome, on Ubuntu. When I went to do a test on the part of the system (place) where we took a picture of the webcam, instead of displaying the authorization message…
-
6
votes1
answer190
viewsQ: Difference between "list(range(1, 10))" and "range(1, 10)"?
I asked that question here How to format all elements of a list in Python?. In one of the answers, @Ciganomorrisonmendez, put the following excerpt: list(range(1, 10)) But every time I used the…
-
5
votes2
answers1685
viewsQ: How to format all elements of a list in Python?
In php, when I want to generate a array formatted, I use the function array_map. Thus: $numeros = range(1, 10); array_map(function ($value) { return sprintf('%04', $value); }, $numeros); Returns:…
-
1
votes6
answers886
viewsQ: Regular expression to grab the background-image url
I’m not very good yet of regular expression. How could I do to capture only the contents present within the snippet url() of background-image? Example: $elemento.css('background-image'); //…
-
27
votes3
answers14943
viewsQ: A Base64 image loads faster than a url?
I am developing a page where I need to have the images displayed only after loading them. And, not to leave the space of the empty images, I thought to use some image of "Loader". So, I thought that…
-
5
votes2
answers1064
viewsA: How to use $(this) + checked?
There is also another way, which is using the function filter. Thus: $(function (){ $("[name='teste1']").click(function () { alert($(this).filter(':checked').val()); }); }) <script…
-
11
votes2
answers1423
viewsA: Javascript - Access variable
In the case of accessing the function variable previously to the declared scope, I would suggest that you do this in the function property, as it would become difficult or impossible to access the…
-
8
votes1
answer522
viewsA: PHP script paging
Very simply: $page = isset($_GET['page']) (int) $_GET['page'] : 1; $limit = 10; $offset = ($page * $limit) - $limit; // Gera 0,1,2,3, para cada página incrementada $stmt = $pdo->prepare("SELECT *…
-
2
votes1
answer62
viewsQ: Validate method name by suggesting the correct one
I am using a framework email library class Nette. Then at some point, instead of calling the method setSubject - which is the correct method, I called addSubject, because I had forgotten the name of…
-
20
votes3
answers3474
viewsQ: Why is it sometimes necessary to setTimeout with a value of 0 (zero)?
I have observed for some time that some types of event only work correctly when we define a certain function that is called with the setTimeout worthwhile 0. On the contrary, if we call this…
-
2
votes1
answer473
viewsQ: What is the Deferred Object in jQuery for?
I’m studying a little jQuery and I found that interesting. The problem is I don’t quite understand. What is the Deferred Object in jQuery for? How this can become useful when using jQuery?…
jqueryasked Wallace Maxters 102,340 -
2
votes5
answers3336
viewsA: How to mix an array in Javascript?
Using the @Gabrielrodrigues response, I was able to get a result using the function sort. Thus: a = ['@wallace', '@rray', '@cigano'] a.sort(function (a, b){ return Math.floor(Math.random() * 10);…
-
5
votes5
answers3336
viewsQ: How to mix an array in Javascript?
In PHP, when I need to mix an array, I use the function shuffle. Thus: $a = array('@wallacemaxters', '@rray', '@CiganoMorrisonMendez'); shuffle($a); print_r($a); exit: Array ( [0] =>…
-
0
votes1
answer688
viewsQ: Is there any way of knowing where the function was called?
If I have a huge project and I realize that somewhere in the code, a function is being called, but I don’t know where it is, is there any way to find out? Example: #index.php // nada aqui nesse…
-
1
votes1
answer266
viewsQ: Is there any way to know how many times the function has been called?
I wonder if in PHP there is any way to find out how many times a certain function has been called. I speak natively as I would also like to do this check for native functions. Example:…
-
1
votes2
answers545
viewsA: Problem accessing a One to Many interface in Laravel
Rafael, by the return you show me you Not Selected the field related to the relationship, if you used the function select. The problem is that Laravel 4 can’t relate items internally when you don’t…
-
3
votes12
answers28737
viewsA: What are the ways to iterate an array in PHP (without foreach)?
It was said in the previous answer that array_map disregard the index. However, there is another very interesting way. It is using array_map, with multipos parameters. Thus, we can pass an array…
-
3
votes7
answers3681
viewsA: What are the implications of not declaring variables in PHP?
In general, there is no implication. PHP is a weak typing language. Usually in the languages where the types should be declared they are required to be declared. Another case is javascript, because…
-
24
votes5
answers1499
viewsQ: What is a gluttonous regular expression?
What is a Expressão Regular Gulosa? What sets her apart from Expressão Regular Não-Gulosa? Expressões regulares Gulosas consume more resources than Não-Gulosas?…
regexasked Wallace Maxters 102,340 -
26
votes2
answers534
viewsQ: What can make a regular expression slow?
It’s happened here in the Stackoverlow I am recommended by some users to avoid the use of regex, in some cases as it may have undesirable performance. I have also heard that, depeded in the way that…
regexasked Wallace Maxters 102,340 -
6
votes2
answers766
viewsQ: What is 1 for in regular expression, in javascript?
I was taking a look at this @Sergio response here at stackoverlow: /a/93995/4995 There was an excerpt of code like this: /^(\d)\1+$/.test(111) What exactly does the \1 in that regular expression?…
-
1
votes2
answers2657
viewsA: Regex to pick sequence of equal numbers
If you want to check if the numbers are in sequence, with 4 or more repeats, you can do so: /^(\d\d)\d{0,4}\1$/.test(1222); // FALSE /^(\d\d)\d{0,4}\1$/.test(122222); // TRUE If you want to increase…
-
4
votes1
answer336
viewsQ: What is the purpose of { } (keys) to be used to delimit PHP code?
In PHP, you can use the keys in any code snippet, for example, to separate blocks aesthetically. Example: { $a = 1; } { class X{} } { { function x() {} } } In these examples, none of them an error…
-
0
votes3
answers436
viewsA: What is the purpose of array_map to accept infinite array parameters after callback?
The purpose is to map all arrays at the same time. This can be useful when it is necessary to apply a "merge" in certain arrays, so that you could better control the output. A small example, where…
-
6
votes2
answers1244
viewsA: How to loop with while using array
As told by @rray, you can do this using WHERE IN Thus: SELECT * FROM medias WHERE id IN(1,2,3,4,5,6,7,8,9) Another possible way would be using the implode function, to join the elements of the array…
-
1
votes3
answers436
viewsQ: What is the purpose of array_map to accept infinite array parameters after callback?
I usually use the function array_map to be able to do something similar to the "list comprehension" of python Something like: $meses = function($mes) { return sprintf('02%s/%s', $mes, date('Y')); }…
-
4
votes1
answer61
viewsQ: Is there any way to make an exception when fwrite cannot write?
I usually use the class SplFileObject to be able to work with files. The same does not happen with sockets, when necessary to connect, it is necessary to use the function fsockopen or…
phpasked Wallace Maxters 102,340 -
14
votes4
answers3299
viewsQ: Typing the return in PHP 7. What are the advantages?
I was giving a test in PHP 7 and I checked that the same now accepts to define which type of data will be returned. Here are some tests: Defining the instance to be returned function test_object():…
-
10
votes1
answer112
viewsQ: what influences Google indexing time?
When I had a blog on Blogger (Blogspot), I noticed that it took from 1 to 3 days for the content to be indexed by Google. However, those days ago, I asked a question here on Stackoverflow that, with…
seoasked Wallace Maxters 102,340 -
2
votes3
answers1016
viewsA: Read Array out of foreach
To do this use the function print_r. example: $meu_array = array(1, 2, 3); print_r($_POST); print_r($meu_array); // Array (3) { 1, 2, 3 } You can also use the function implode echo implode(',',…
phpanswered Wallace Maxters 102,340 -
9
votes4
answers301
viewsQ: How to find hashtags in a string and store them in an array?
I have a content posting system on a particular social network of our company. When the user type the text with hashtags, I need to detect all of them and store them in an array. Example: Hi, I’m…
-
1
votes2
answers126
viewsQ: How to remove the "date" we set in jQuery?
In jQuery, it is possible to define values for an attribute through the data. Thus: $('body').data({id: 1, nome: 'stack'}); And the result of that would be: console.log($('body').data()); // {id: 1,…
jqueryasked Wallace Maxters 102,340 -
5
votes2
answers1574
viewsQ: Is there any way to configure the image quality to increase the upload speed?
Is there any way to leave a particular image, through CSS, with a lower quality, to increase the page loading speed? Example: First load a certain image with lower quality, then increase the quality…
-
1
votes2
answers130
viewsA: How to use the find with sum method?
If the values of the fields are returned in the index of an array or object, then you should probably use a alias for SUM(valor_pago). So you will be able to access the values returned from the…