Posts by Daniel Omine • 19,666 points
581 posts
-
2
votes6
answers650
viewsA: How to extract a variable from within a function
When you need to declare a global variable within a function, you must specify the depth from which the object will be instantiated. To declare within the global scope, declare with the prefix…
-
1
votes2
answers877
viewsA: How to create field dynamically with jQuery?
Simple example, where a input of the kind text is added to the body $('<input>').attr({ type: 'text', name: 'nome_do_campo', value: 'teste valor' }).appendTo('body'); If you want to add to a…
-
1
votes3
answers1350
viewsA: PHP $_FILES[''] becomes empty before validation
In the global variable $_FILES[], before making any kind of access to the parameters, you should check the value of the parameter error. Example if( $_FILES["avatar"]['error'] != UPLOAD_ERR_OK ) {…
-
5
votes3
answers2715
viewsA: Is there any way to display the size of the string in a MYSQL result?
It depends on which measure you want to get. There are the functions LENGTH() and CHAR_LENGTH(). The function LENGTH() calculate the measure in bytes. The function CHAR_LENGTH() calculates the…
mysqlanswered Daniel Omine 19,666 -
1
votes2
answers326
viewsA: Problem with margin-left in Internet Explorer
1. Missing defining elements to be displayed as inline. To do this, use the parameter display. Example: display:inline. However, if you want to customize margins and spacings (padding, margin),…
cssanswered Daniel Omine 19,666 -
8
votes4
answers25607
viewsA: Load page and scroll automatically to a particular element
In the header, <head></head>, add between the tag <script></script> the following code: $(document).ready(function() { window.location.href='#foo'; }); The method ready()…
-
1
votes3
answers3438
viewsA: How to receive a pdf file via ajax?
The question asks for a solution via ajax, however, the intention is to execute an action at the end of the download so I present a simple solution: Full example: <html> <head>…
-
3
votes2
answers97
viewsA: What does the expression "for x in *" do?
The asterisk indicates the reading of everything in the folder. The variable X receives the names of the individual files, which are printed by the constructor echo.…
bashanswered Daniel Omine 19,666 -
6
votes3
answers2129
viewsA: What is the simplest way to create a mask for numbers in PHP?
Generic formatting with dynamic mask: function format_string($mask, $str, $ch = '#') { $c = 0; $rs = ''; /* Aqui usamos strlen() pois não há preocupação com o charset da máscara. */ for ($i = 0; $i…
-
4
votes3
answers1611
viewsA: Dynamic property name in Javascript
If you only want to create and access variable properties, that is, create and access properties of an object dynamically, just use the brackets: var a = 'foo'; var b = 'bar'; var myObj = new…
-
4
votes1
answer369
viewsA: Tag <video> controlling by javascript
The method name is play(), however, you should access it from the DOM tree because it is not a Jquery method but a DOM Object method. jQuery( document ).ready(function($) {…
-
1
votes6
answers392
viewsA: How to make a explode without returning empty values?
Get a basic treatment before using the explode(). Below, an example with trim() and strpos() $str = '/a/b/c/'; $str = trim($str, '/'); if( strpos( $str, '/' ) ) { $arr = explode('/',$str);…
phpanswered Daniel Omine 19,666 -
1
votes4
answers3237
viewsA: Calculate and convert byte file size to kB, MB, GB, etc
The base calculation is 1024 because 1kb is 1024 bytes. Based on this, create a function that determines the type of measure. /* 1024000 bytes = 1 kilobytes 1000 kb = 1 megabyte 1000 mb = 1 gigabyte…
phpanswered Daniel Omine 19,666 -
1
votes3
answers1782
viewsQ: Enable and disable an event without deleting and recreating it
Is there any way to disable and activate an existing event in an object? Example, I have an event in an element <img onclick="foo();"> On this same page, there is an action where, while…
-
3
votes2
answers22624
viewsA: How to download from command prompt?
There are several ways to solve. If you want something similar to *Nix systems, there is the wget for windows: http://gnuwin32.sourceforge.net/packages/wget.htm For those who are used to it, there…
-
4
votes1
answer40
viewsA: What does the setCell command in javascript
The method .setCell creates a cell/column of a table <td></td>. The first parameter represents the column index ColumnIndex. The second parameter represents the line index (Row)…
-
3
votes2
answers1076
viewsA: Format decimal in monetary value
A practical example with 2 functions that simplify formatting in a very generic way: <html> <head> <script type="text/javascript"> function number_format(number, decimals,…
javascriptanswered Daniel Omine 19,666 -
3
votes1
answer134
viewsA: What’s the Splstack class for?
The SplStack is a class in the standard PHP library (SPL -> Standard PHP Library). Belongs to the data structure group: http://php.net/manual/en/spl.datastructures.php About what this class does,…
-
4
votes2
answers400
viewsA: use regex in php explode function
The function explodes is not appropriate for this. You can get the result you expect with the function preg_match_all $str = '"olá mundo" "oceano pacifico"'; if…
-
2
votes2
answers131
viewsA: Extract key/value pair from querystring
It is more practical using the function parse_str() due to the format of the string. However, the original script was almost there.. Just fill an associative array instead of concatenating the data…
-
0
votes4
answers179
viewsA: How to display files without underline?
//não exibe a imagem, por quê? echo "<img src=". $num .">"; The result of this will be <img src=criança com bolo.jpg> HTML will interpret the end of the file in the first space…
phpanswered Daniel Omine 19,666 -
1
votes1
answer59
viewsA: Does anyone know where I can find this php?
This has nothing to do with PHP itself, as this is an issue related to specific files of a system or framework customized and unknown, judging by the file nomenclature and code style. Consult the…
-
4
votes13
answers20263
viewsA: What makes a language to be considered low/high level?
I believe that the polemics and disagreements are due to the term used "low level" and "high level". I think a more appropriate term could be "low layer" and "high layer" i.e., "low layer" and "high…
-
5
votes3
answers1212
viewsA: Why can’t we destroy [using unset in] a static variable?
The function unset() is for array elements, variables and object attributes. It is not possible to exclude a property from a class declared in the scope of the class, regardless of the declaration…
-
0
votes3
answers3409
viewsA: How to receive a POST without the <form> tags in PHP?
A simple and safe technique is to create the element <form> "on-the-fly" (at runtime). See an example without using a framework or ajax: <html> <head> <script…
-
10
votes1
answer415
viewsA: Why should we use functions that start with mb_?
The PHP functions whose nomenclature starts with "mb_" belong to the functions Mbstring MB stands for "Multibyte", that is, they are functions for manipulating multibyte strings. Encodes like UTF8…
phpanswered Daniel Omine 19,666 -
2
votes3
answers4210
viewsA: Send form without using PHP or similar
First of all, every language is dynamic. What you probably meant is "language that runs on the server side". A simple way to resolve your issue is to use HTML "mailto". Example: <a…
-
3
votes2
answers470
viewsA: Is it necessary to bar " " at the beginning of native functions when using namespace?
Not mandatory, but necessary to avoid name conflicts or when you need to directly access names in the global scope. http://www.php.net/manual/en/language.namespaces.global.php…
-
0
votes2
answers860
viewsA: Help with PHP Stack
First version $arr[1] = [1,2,3,4,5,6,7,8,9,10]; // Pilha 1 $arr[2] = $arr[1]; // Pilha 2 /* Remove os números ímpares da pilha 1 */ foreach($arr[1] as $k => $v) if($v%2==0) unset($arr[1][$k]); /*…
phpanswered Daniel Omine 19,666 -
3
votes3
answers423
viewsA: How to choose a digital certificate? What to take into account?
The basic point is to check for browser compatibility. In fact no one needs to buy SSL certificates as they can be generated for free. The problem is that popular browsers do not recognize such…
-
1
votes2
answers485
viewsA: How to send record only once in INSERT
In order to avoid multiple submissions of the same form, basic recommendations follow below: 1. Disable form submission Once done the action of "Submit", disable it. Example of technique using…
-
3
votes1
answer974
viewsA: Translation of pages into php files
It works smoothly as shown, but I recommend that you use array and avoid including directly in the pages because there may be collision of variable names. Recommendations 1. Nomenclature of…
phpanswered Daniel Omine 19,666 -
7
votes2
answers4997
viewsA: What are the differences between __autoload and spl_autoload_register?
The function __autoload() works as magical methods like the __construct(), __destroy(), __string, etc.. __autoload() captures the name of an undeclared class. With the class name, simply mount the…
-
5
votes2
answers2244
viewsA: What is the right way to save images to a server?
I use a technique I learned from the structure of an EC platform called Prestashop. It’s a bit complicated to explain, so I’ll show you an example. Also, I don’t know if there’s an appropriate term…
-
3
votes1
answer131
viewsA: php usort, sort table of brasilerão
Using the array_multisort function() Example /* pts -> points (pontos) win -> victories (vitórias) gd -> goals difference (saldo de gols) gp -> goals pro (gols pró) gc -> goals…
-
2
votes2
answers800
viewsA: How to get the CSS that was defied on another page?
I could do it this way <link rel="stylesheet" type="text/css" href="cliente[$cliente].css"> That’s all it takes, I wouldn’t need the if parole. Obs: in place of [$cliente], put the variable…
-
1
votes3
answers1202
viewsA: Remove a letter from the alphabet with FOR
In a different approach, a simplified and optimised proposal: <?php $remove = 'y'; $str = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z'; echo str_ireplace(array(','.$remove,…
phpanswered Daniel Omine 19,666 -
5
votes3
answers11223
viewsA: What is the MINUS command for and how it works on oracle
The Oracle MINUS command has the meaning of "exception". It is usually used to delete data that returns in a query. Do not confuse with deleting data like DELETE. It is something quite different.…
-
1
votes1
answer220
viewsA: DLL php_http.dll using windows
The library php_http is out of date for more than 6 years. It is incompatible with versions of PHP released since then. It is recommended to use the library CURL.…
-
2
votes3
answers3371
viewsA: Query value within a variable
Check function mb_stripos() Function Mb_* are functions of the library MBSTRING, are functions that provide multibyte character support. The letter "i" in the function name, indicates "marry…
phpanswered Daniel Omine 19,666 -
0
votes1
answer556
viewsA: POO with PHP $_POST
Redeem the parameter received by the post method $transaction_code = $_POST['transaction_code']; Once done, pass to the class method parameter:…
-
1
votes2
answers1394
viewsA: Mysql returns only the first record
The "Return" command interrupts the execution loop in the first loop, so it is only returning the first record it finds. Change return for echo and see the difference return…
-
2
votes2
answers333
viewsA: Making multiple SQL inserts, multiple Inserts
The problem lies in the execution of multiple inserts and the wrong mode as mounted the queries, mixing variables out of scope. By default, SGDB (Mysql) does not allow multiple queries in a single…
-
1
votes2
answers425
viewsA: Redirect or deny direct access to public folder
Whereas the Directive RewriteBase is the root of http://localhost/, add the following rule: RewriteRule ^(public/) - [F,L,NC] This rule will deny access to public/folder. If you want to add another…
-
1
votes1
answer608
viewsA: How to access a function variable in another function
In Cakephp version 1.2.x: $vars = ClassRegistry::getObject('view') -> viewVars; echo $vars['x']; // o nome do índice é o nome da variável que deseja acessar. To use it is necessary to extend the…
-
4
votes5
answers667
viewsA: Use JS to relieve PHP
Validations should be made in PHP (server side) regardless of what happens on the client side (js, html). To "ease" processes, it is recommended to apply Javascript validations to avoid server…
-
1
votes1
answer90
viewsA: GD does not work on file created in UTF-8
When using UTF-8 make sure to remove the BOM character (bit order mark). To do this, using the text editor itself, set the charset to "UTF-8 Without GOOD". This feature depends on the editor you…
phpanswered Daniel Omine 19,666 -
2
votes5
answers26812
viewsA: When is isset required?
Always use when a variable comes from the user, but it’s also good to always check even if the data comes from the application itself. When you do $saldev = $_POST ["Tdate5"]; It is causing an error…
-
1
votes2
answers431
viewsA: PHP does not take the auto-fill values
Error is due to method defined in tag . Is like GET <form method="get" action="."> Switch to POST <form method="post" action=".">…
-
-1
votes2
answers520
viewsA: Check where the POST came from
Something effective is to check the "dns Reverse lookup". On your hosting provider, set up or ask to set up "dns Reverse lookup" or "reverse dns" in English. So whenever you receive a request (POST,…