Posts by Pedro Sanção • 5,639 points
147 posts
-
4
votes2
answers2558
viewsA: How to get the value of inputs by declaring this of an element [jQuery]?
No need to use .serialize(). You can access directly from this, in the case of forms HTMLFormElement. Fields can be accessed in 3 ways: on the property name country: this.nome_do_campo through…
-
3
votes2
answers7764
viewsA: Lock special characters but allow hyphen
add the hyphen as the last class character, so it is not necessary to escape it: new RegExp("^[ 0-9a-zA-Zàèìòùáéíóúâêîôûãõ\b-]+$"); Your code only removes the last character from the field, this…
-
2
votes2
answers986
viewsA: regular expression replacement - reference followed by number
Short answer: depends on implementation. In the editor gedit (python syntax) was accepted as a replacement: \g<1>3. In the Netbeans (which is done in Java) the replacement was done correctly…
regexanswered Pedro Sanção 5,639 -
1
votes1
answer385
viewsA: Run function after loading all scripts in pure Javascript
I notice you assign a function to the event load after inserting the resource with .insertBefore(). In this way it is possible that the function assigned to the event load never run, as the event…
-
8
votes2
answers273
viewsA: .after() jquery on JS Pure?
The jQuery function .after() inserts a sibling element later, in native javascript this is done with insertBefore(), according to the documentation: (insertBefore) Adds the specified node, before a…
javascriptanswered Pedro Sanção 5,639 -
3
votes2
answers1497
viewsA: Delete file in php at specified frequency
You can use strtotime() to set the time from a period and compare with the result of filectime(), which returns the creation date on Windows servers (source). In your example you used fileatime(),…
phpanswered Pedro Sanção 5,639 -
2
votes1
answer99
viewsQ: how browsing-context works (browsing context)
I was reading the attribute documentation target of the HTML element <a>: (...) In HTML5, it is a name or keyword that refers to a browsing context (for example tab, window or frame) (...)…
html5asked Pedro Sanção 5,639 -
3
votes1
answer99
viewsA: how browsing-context works (browsing context)
The browsing context can be understood as an instance (or session) of the browser, it can be a window, a tab or a <iframe>, with independent browsing history. In HTML 5 a context is created…
html5answered Pedro Sanção 5,639 -
1
votes2
answers600
viewsA: Open iframe link after post PHP + JS
Use the attribute target of link or of form, with a value equal to that of the attribute name of <iframe> <a href="/" target="exemplo">pt.stackoverflow.com</a> <form action="/"…
-
3
votes1
answer68
viewsA: How to pick up points of interest between two moments in time?
PHP (>= 5.3.0) provides some time handling classes that can help: DateTime and DateInterval. <?php function pontosInteresseIntervalo($inicio, $fim) { $dateInicio = new DateTime($inicio);…
phpanswered Pedro Sanção 5,639 -
1
votes2
answers688
viewsA: Difference of days javascript considering dates in different months
The problem with your code is the month, which is indexed to zero, but you’re subtracting from the day. In addition the split result can return an unexpected number, so it is necessary to round with…
javascriptanswered Pedro Sanção 5,639 -
1
votes2
answers5870
viewsA: Insert gif 'loading' while performing function
You can make an animation "loading" with CSS only (no GIF images): @-webkit-keyframes spinning { from {transform: rotate(0deg);} to {transform: rotate(180deg);} } @keyframes spinning { from…
-
4
votes6
answers11785
viewsA: Is there an advantage to using filter_input instead of isset?
There is a bug (reported on 24/03/2012) related to the function filter_input(). Some values of $_SERVER are not displayed correctly. The code snippet below displays the keys where the problem…
phpanswered Pedro Sanção 5,639 -
1
votes1
answer1943
viewsA: Opening HTML inside a DIV does not recover the parameters via GET
I realized you’re trying to get a value you already have (cod is in the attribute onclick). These values can be accessed in javascript through the attributes data-* where * may be replaced by a.…
-
0
votes2
answers621
viewsA: How to pick up and count images with php?
PHP groups files sent with the same name in an intuitive way, I created a function (https://gist.github.com/pedrosancao/9100827) which interprets the received values in a way that allows the…
-
3
votes1
answer685
viewsA: Bevel[Bevel] effect on PS text in CSS
From the contents of that reply by Soen it is possible to approximate the effect with the CSS property background-clip: text. Although it works on some browsers, this property value is not specified…
-
3
votes1
answer941
viewsA: Radiobutton and Checkbox Soma
The structure of your code does not consider when a radio is unchecked when selecting another radio, which causes the problem of not subtracting. As I think it would be complex to control the fields…
-
2
votes2
answers5542
viewsA: How to validate a zip code using jQuery.validate
Change the regular expression to: /^[0-9]{5}-[0-9]{3}$/ The value between keys defines the amount of times the characters in brackets will repeat, thus validating the value 11.111-11 with…
-
1
votes1
answer151
viewsA: Javascript Check Box
Change the code to $(function(){ $("#selecionar-todos").change(function() { $("#lista input:checkbox").prop('checked', this.checked); }); $("#lista input:checkbox").change(function() { if…
-
2
votes3
answers1036
viewsA: Grab last key from auto increment PDO
If the table has a primary key with autoincrement you can consult the value of the next record that will be inserted with the query below, because the value of AUTO_INCREMENT is not amended by line…
-
3
votes1
answer688
viewsA: Is there any way of knowing where the function was called?
The function debug_print_backtrace() displays the call stack to the point where the function is executed. Although the documentation does not show, this function receives an optional parameter with…
-
2
votes1
answer360
viewsA: What are the risks of saving files to the Apache server with PHP and how to avoid them?
Saving files on the server is safe as long as it is configured correctly. Using 777 permission is bad practice, but sometimes it is the only alternative when there is no access permission root. The…
-
0
votes2
answers704
viewsA: Error replacing occurrence in string using replaceAll
Observing the function signature String.replaceAll(): public String replaceAll(String regex, String replacement) The mistake Illegal Character range is caused because the function interprets the…
-
1
votes2
answers165
viewsA: Friendly URL changing file link
your CSS must be with a relative path and will be interpreted from the last bar of the page address <link rel="stylesheet" href="css/principal.css"/> So depending on which page to open the…
phpanswered Pedro Sanção 5,639 -
2
votes2
answers2561
viewsA: Captcha reader in Portuguese - Google noCaptcha reCaptcha
So far there is no translation of reCaptcha audio, only the texts are translated. According to the guide, there is the GET parameter hl for language configuration. Example: <script…
-
1
votes1
answer417
viewsA: Show Image inside another
Since all data is in the same table (ifsp) you can add the photo to the image of the wallet you created using imagecopyresampled (untranslated), this way eliminates the need to overlap the two…
-
3
votes4
answers842
viewsA: Write MYSQL data in en / UTF8 format
There are two ways: by DNS; by command SET NAMES (that can be executed on startup) The ideal is to use both, because before PHP 5.3.6 the parameter charset of DNS was ignored. <?php $dsn =…
-
1
votes1
answer254
viewsA: How to set the path to access files on procedural system
I usually create a file define.php, with directories, using previous settings, much like the OS example, always finishing the bar setting. <?php define('ROOT_DIR', filter_input(INPUT_SERVER,…
phpanswered Pedro Sanção 5,639 -
1
votes2
answers834
viewsA: Optimization of Mysql connections
Use persistent connections: Persistent connections are connections that do not close when your script runs out. When a persistent connection is requested, PHP checks for an identical persistent…
-
3
votes1
answer43
viewsA: Function that makes the direct $foo[array_rand($foo)]
Short answer: No. There is no native function to return a random value of the array according to list of functions of array.…
-
3
votes2
answers132
viewsA: I couldn’t understand the new cpaint()
I’m not sure if it answers the question, but it should clarify how the keyword works new. This is the way to simulate object orientation in javascript. The variable type cp will be object due to…
javascriptanswered Pedro Sanção 5,639 -
3
votes4
answers850
viewsA: Return all equal items from different groups
The only way I know how to do it is with GROUP_CONCAT, and as it is not possible to do Join with calculated fields will be required two Subqueries (can even create an view): SELECT t2.* FROM (…
-
4
votes1
answer877
viewsA: Command to delete all folders except the three most recent
Use the command ls -t diretorio/sub_diretorio | tail -n +4 | xargs rm -r ls -t list the files sorted by date, latest first tail -n +4 displays from the 4th element of the list, ignoring the first 3…
-
8
votes3
answers27643
viewsA: Get checkbox values with javascript
You can use the function document.querySelectorAll(), which takes as parameter a CSS selector and returns the combined elements. Use the selector :checked to iterate only the checkbox marked.…
javascriptanswered Pedro Sanção 5,639 -
10
votes6
answers14587
viewsA: Show the largest and smallest number
You can use the functions Math.max() and Math.min(). The two functions receive all values for comparison as parameters. Although the question is why it is wrong, this form will make your code more…
-
4
votes6
answers650
viewsA: How to extract a variable from within a function
there are two ways 1 - Declaring out. That way the code becomes simpler to understand and you can control the scopes explicitly. var foo; // declaração fora function teste() { foo = 'valor'; // sem…
-
3
votes2
answers374
viewsA: What are the valid delimiters for preg_regular expressions?
Of http://php.net/manual/en/regexp.reference.delimiters.php: A delimiter can be any non-alphanumeric, non-backslash, non-whitespace Character. (free translation) A delimiter can be any…
-
5
votes1
answer860
viewsA: Menu with vertical and horizontal balls
To do this it is necessary to use the function counter() of property content within CSS pseudo-element ::before of each item in the list. (Documentation). For positioning use margins, padding and…
-
1
votes1
answer141
viewsQ: CSS - how to make numbering of all levels in nested lists
How to make nested list numbering include parent element numbers (all levels), using CSS only? By default lists only display the numbering of one level: <ol> <li>item <ol>…
cssasked Pedro Sanção 5,639 -
3
votes1
answer141
viewsA: CSS - how to make numbering of all levels in nested lists
To do this it is necessary to use the function counters() of property content within CSS pseudo-element ::before of each item in the list. Source:…
cssanswered Pedro Sanção 5,639 -
4
votes4
answers7995
viewsA: Accentuation is unreadable on the page
According to that answer the charset sent by the HTTP header Content-type takes precedence to charset informed by metatag, possibly why change the meta tag did not resolve, check the response…
-
2
votes6
answers392
viewsA: How to make a explode without returning empty values?
No need to use regular expression, use array_diff(), I think it’s the shortest way to do: <?php array_diff(explode('/', '/pagina//id//1'), array('')); // resultado: array ( 1 => 'pagina', 3…
phpanswered Pedro Sanção 5,639 -
3
votes4
answers824
viewsA: Regular Expression to get what’s outside of brackets
My suggestion is to use denied classes to match "everything that is not bracket": [^\[]+ and [^\]]+. Gathering and placing the groups was: ([^\[]+) (\[([^\]]+)\]) Example: var str = 'Itaú 1…
regexanswered Pedro Sanção 5,639 -
13
votes2
answers133
viewsQ: get original HTML entities with javascript
I need all the original HTML entities of a paragraph, mainly the accents, the methods I know only recover some entities, as the example below where ">" is correctly coded but "ç" does not. It is…
-
4
votes1
answer159
viewsA: Regex - Very high replace process time
Maybe change the quantifier [^\~]*? for [^\~]* resolve. The quantifier "not greedy" *? (Lazy) makes for each married character, the search will test the rest of the regular expression, so the delay.…
-
7
votes3
answers605
viewsA: Metro style checkbox
It is possible to do exactly the same as the example using the selectors + (adjacent) and ::after, and a trick with edges to create the triangles .metro label { display: block; margin: 5px; padding:…
-
10
votes2
answers188
viewsA: Is there a jQuery selector that takes the html from its own tag and also the content?
jQuery does not have this function, but it is possible to use the property Element.outerHTML, as it is a property of the javascript object (and not jQuery) it is necessary to take the element with…
-
2
votes2
answers1316
viewsA: Monitor PHP script processing
It is possible to link a function to the event Progress of XMLHttpRequest, it is necessary to check if it is possible to calculate the size of the answer, which is received through the header…
-
0
votes2
answers433
viewsA: get word in given coordinate (x,y)
I found the solution based on in that question from Soen from the @Maiconcarraro response. I used the function document.caretRangeFromPoint(x, y), which creates a text selection in the infomada…
javascriptanswered Pedro Sanção 5,639 -
0
votes1
answer122
viewsA: How to collect 'data-userid' from an Ajax-generated Button and use 'data-userid' in a post?
jQuery provides the function .data() to fetch attributes data-*. In your code change var id_usuario = $(this).attr('data-userid'); To var id_usuario = $(this).data('userid'); another error that may…