Posts by Daniel Omine • 19,666 points
581 posts
-
1
votes1
answer254
viewsA: Error with getimagesize in photo upload
In this section of the original code, $imagem = $_FILES["imagem"]; Modify to $imagem = $_FILES['imagem']['tmp_name']; The above example is considering an image only. Multiple image upload requires a…
-
0
votes2
answers41
viewsA: How not to have Warning if I leave empty in the formula multiplication discount?
The divisor cannot be zero because no number is divisible by zero. Here’s an example of how you can solve by applying a ternary conditional. <?php echo round( 100 - ($deal_price >…
-
1
votes1
answer559
viewsA: Extract data from a facebook profile by searching for email
<?php date_default_timezone_set('Asia/Tokyo'); ini_set('error_reporting', E_ALL & ~E_STRICT & ~E_DEPRECATED); // & ~E_NOTICE ini_set('log_errors', true); ini_set('html_errors',…
phpanswered Daniel Omine 19,666 -
1
votes2
answers150
viewsA: Is this kind of normalization feasible?
I suggest something modular, avoiding linking the structure to localized business rules. As an example, I would not create 2 tables, one for CPF and one for CNPJ, even if it was a localized system.…
-
1
votes4
answers7723
viewsA: Check for number in a string
The question does not specify whether you want to get the position of what you find as numeric, so by focusing on the section that says you only need to find if there are numeric characters, you…
phpanswered Daniel Omine 19,666 -
7
votes2
answers3526
viewsA: Why is 'ç' converted to %C3%A7 URL, not %E7?
The RFC 3986 does not specify which encoding should be used for non-ASCII characters. The URL encoding involves a pair of hexadecimals, which is equivalent to 8 bits. It would be possible to…
urlanswered Daniel Omine 19,666 -
-1
votes2
answers953
viewsA: It is wrong to use common variables within a PHP class
There’s no problem and it’s not wrong either. What can be "wrong" is using local variables for resources that could be shared. Example of something not at all intelligent: class foo() { private $a;…
-
2
votes2
answers230
viewsA: Direct cast or cast functions. What is the best option?
Testing with casting Summary: 40531158 * 106 (4 millionths) // /* O tempo tem uma variação 0.0000028610229 0.0000038146973 Normalmente entre 0.0000040531158 e 0.0000050067902 */ $v = 42; echo…
-
4
votes1
answer94
viewsA: How to return a valid result from a PHP operation?
You cannot use operators as variables because operators are constructors. It cannot be passed as string or object or anything like that. A single means viable would be the use of eval(). A "smart"…
-
1
votes1
answer163
viewsA: Remove several percentages proportional to a single value
The problem is in the percentage formula. ($recipientAmount * $totalAmount) / 100 Should be ($recipientAmount * 100) / $totalAmount This is enough to solve the problem. If you want to know more,…
phpanswered Daniel Omine 19,666 -
1
votes2
answers5070
viewsA: How to display a certain position of an associative array?
This repeat loop iterates the integer array and displays the associative key and its value. foreach ($vetor as $k => $v) { echo $k.' -> '.$v.PHP_EOL.'<br>'; } If you wanted to display a…
-
2
votes3
answers4603
viewsA: Check that the value is integer
The number 1 is int but 1.0 is not int, is a float or may also be double or decimal depending on the language. Understood the difference? So 1.0 or 1.0000, will never be a int. Check with a test…
phpanswered Daniel Omine 19,666 -
4
votes1
answer84
viewsA: Doubt about the theoretical part of web services
In this program, I created the web service by Eclipse and an application Android to consume the web service. In this case, my web service and Android app are simply service provider and requester,…
web-serviceanswered Daniel Omine 19,666 -
1
votes4
answers3793
viewsA: How can I put a negative number in PHP?
If you want to turn an existing variable into a negative value, programmatically multiply by -1. This is basic mathematics. $x = 10; /* aqui faz as firulas e tal.. */ //em algum ponto vc quer mudar…
phpanswered Daniel Omine 19,666 -
1
votes2
answers213
viewsA: How to avoid excessive line breaks in a textarea
The question is vague, but it might solve: preg_replace("/[\r\n]+/", "\n", $string_recebida_do_textarea); Example of how it works: //Simulando uma string com várias quebras de linha $str = ' a b c…
-
1
votes1
answer479
viewsA: I would like to insert a javascript Alert into my action button
Inline example: <a href="delete.php" onclick="return confirm('Prosseguir com a ação?');">excluir</a> To be more clear, for your case: <?="<td><a href=".$url_excluir."…
-
0
votes2
answers54
viewsA: Error converting to vector (->toArray()) in Cakephp
If you want to get a group nested result, In this passage $query = produtos_model->find() ->where(['data' => $data]); //Converte o resultado para um array. $produtos = $query->toArray();…
cakephpanswered Daniel Omine 19,666 -
2
votes1
answer916
viewsA: Problems with PHP Json Encode?
When the array indexes are all numerical, the json_enconde() does not return the pair "chave":"valor" and presents only the values, ordered by the index. A clearer example: $array = array(0 =>…
-
1
votes1
answer84
viewsA: Apparently global variable does not store the entire mysqli_query output
There are a lot of things wrong, but I will refrain from commenting on the points outside the main purpose of the question. So let’s get to the point. The function list_dataset(), modify in this…
phpanswered Daniel Omine 19,666 -
1
votes1
answer704
viewsA: Error Object of class stdClass could not be converted to string in codeigniter
It’s unclear where that 49 line is where the error occurs, but I’m guessing it’s on view. The view must be doing something like echo $dados['quest']; and, as $dados['quest'] is a stdClass, this…
-
3
votes2
answers398
viewsA: Why not create a Ruby on Rails distribution that works well on Windows?
Briefly, referring to the question described in the title Why not create a Ruby on Rails distribution that works well on Windows? It is mistaken to say this, because Ror works very well in Windows…
-
1
votes7
answers10590
viewsA: How do I know if today’s date is Saturday or Sunday (weekend) in PHP?
Using the class Datetime $str = null; //$str = '2016-09-24'; $dt = new DateTime($str); $weekend = ($dt->format('w') % 6) == 0; var_dump($weekend);…
-
6
votes1
answer91
viewsA: PHP date_diff error
These are the supported types according to the documentation: const string ATOM = "Y-m-d\TH:i:sP" ; const string COOKIE = "l, d-M-Y H:i:s T" ; const string ISO8601 = "Y-m-d\TH:i:sO" ; const string…
-
-2
votes2
answers1851
viewsA: PHP - Cookies, how to detect if you are created
It’s unclear where you’re invoking the isset(). So the answer presupposes that it’s on the same page you invoked setcookie(). In this case it will not be accessible unless explicitly stated in the…
-
6
votes7
answers21016
viewsA: What does the term Fallback mean?
The very description in English answers. | The fallback locale determines the locale to use when the Current one | is not available. You may change the value to correspond to any of | the language…
terminologyanswered Daniel Omine 19,666 -
2
votes1
answer31
viewsQ: Allow interactivity in Uiscroolview and prevent interaction with content within it while scrolling
Is there any way to prevent user interaction with content within a Uiscrollview? I have a Scrollview the contains Uiviews inside it. In these Uiviews contains only one object, Uiimage. UIScroolView…
-
0
votes2
answers732
viewsA: How to track Curl PHP redirect?
Usually a setup like this is enough // Inicia o cURL $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 5); // tempo em segundos curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // em segundos…
phpanswered Daniel Omine 19,666 -
3
votes3
answers1608
viewsA: Auto Load of classes in PHP
You can optimize by eliminating the technique that iterates an array of directories. $cDir = array('pasta1', 'pasta2', 'pasta3') foreach ($cDir as $dirName) { // aqui vai repetir, buscando nos…
phpanswered Daniel Omine 19,666 -
14
votes1
answer15117
viewsA: What are the differences between Java SE, Java EE and Java ME?
Java SE = Standard Edition It contains the basic features (java.lang, java.io, java.Math, java.net, java.util, etc...). This is usually where learning should begin. Java EE = Enterprise Edition It…
javaanswered Daniel Omine 19,666 -
2
votes2
answers645
viewsA: Create PHP automatic file
Using the PHP Zip library function UnzipFile($file_path, $extract_path) { $zip = new ZipArchive; $res = $zip->open($file_path); if ($res === true) { $zip->extractTo($extract_path);…
-
-1
votes1
answer925
viewsA: Send hidden parameters to another page without showing them in the URL
Whereas the purpose is unknown and disregarding SEO issues, maybe, something that solves is to store in a session variable. In this final chunk, instead of building a URL, save to a session variable…
-
1
votes3
answers205
viewsA: Doubt exercise paper stone and scissors
Just do it like this on the "paper’s probation" else if (computerChoice > 0.33 && computerChoice < 0.67) { console.log("Papel"); Usually there is no resource like if (valor entre x e…
javascriptanswered Daniel Omine 19,666 -
0
votes2
answers1014
viewsA: How can we get the execution time of a script?
In the example of the other answer I used this: class Bench { protected static $ini; public static function Start($id = 0) { /* Get the start time in microseconds, as a float value */…
-
3
votes2
answers299
viewsA: Compared to Datetime class, is the date function more performative?
It is obvious that a resource that consumes more memory will always be more expensive. The more code, even if it is a comma more, it consumes more memory. Example: Teste1 <?php // Teste2 <?php…
-
0
votes2
answers1154
viewsA: Add Information to a file on a specific line
You could use shell commands. In the example below, we use the sed. $file = escapeshellarg('tmp.txt'); shell_exec('sed /5/ a foo '.$file); /* Adiciona "foo" na quinta linha do arquivo A letra "a"…
-
2
votes1
answer672
viewsA: Generate Apache logs in different files
In the folder bin of the Apache exists the rotatelogs This program is useful for generating rotational logs. Apache rotatelogs Here’s an example of how to generate 1 log file per day: <IfModule…
apacheanswered Daniel Omine 19,666 -
1
votes1
answer107
viewsA: Update FTP without the file being removed while overwriting
Usually you make the changes with the system paused, without executions. Because often an update can also modify the database, authentication rules, etc. So in these more critical cases, it is more…
-
2
votes2
answers124
viewsA: Use of loop in codeigniter
Set the name of fields as an array function forms($a){ $r = ''; for(i=0;i<=$a;i++){ $r .= '<input type="text" name="nome_do_campo['.$i.']">'; } return r; } echo forms(5); To receive the…
-
2
votes2
answers7430
viewsA: Calculate time interval in hours and minutes considering different days
Time calculation depends on date. The routine you created does not consider the date, so returns the literal value 11. Here’s a simulation of what you’re doing, but using the PHP native Datetime…
-
1
votes1
answer62
viewsA: Add an initial value to the array
The question asks "add initial value in array" but the right one would be "concatenate value in array items". These are different things. To make it clearer $arr = array() // isso aqui é um array //…
phpanswered Daniel Omine 19,666 -
1
votes1
answer383
viewsA: Identify router template via PHP or Javascript
There are several means but no reliable because it will not always return what is expected. An example of gambiarra you can try to do is get the IP of the user gateway. Normally the gateway IP is…
-
3
votes1
answer57
viewsA: MAX and MIN functions in Cakephp 3
Looking superficially and considering the error message, syntax error, unexpected T_OBJECT_OPERATOR There’s an extra quote: 'MAX(hora) AS 'hora_maxima' Correct by removing the middle quote:…
cakephp-3answered Daniel Omine 19,666 -
0
votes5
answers434
viewsA: Meta Author does not embed when sharing on Facebook
The problem seems to be in HTML semantics, as urged by the facebook message: Fix placing the metatags inside the tag <head></head>. Example: <head> <meta…
wordpressanswered Daniel Omine 19,666 -
0
votes1
answer934
viewsA: System with URL friendly get return in query string
A simple way to solve is just to make a small change to the return URL Your URL is like this: http://outros.local/vendas/carrinhos/finalizada Just do it:…
-
3
votes1
answer537
viewsA: change output type to currency
It is unclear which of the columns you want to apply formatting to, so I’ll show you a generic shape: SELECT FORMAT(12332.2, 2,'pt_BR'); The result is 12332,20. (Without the points) Reference:…
mysqlanswered Daniel Omine 19,666 -
6
votes3
answers1281
viewsA: How can I restrict downloading files through PHP authentication?
You can try the simple medium where PHP reads the entire file and dispatches it to the user. However, this technique has a high cost because it consumes memory, and the larger the file, the greater…
-
2
votes2
answers4124
viewsA: Delete HTML Widget after a few seconds
An example using JavaScript. Basically the script does: 1. Starts execution of processes after full page loading. 2. Sets "empty" visibility after 5 seconds. Important to pay attention when using…
-
1
votes1
answer1076
viewsA: how to make queries passing 2 parameters via Curl?
An example like sending in json format: curl -H "Content-Type: application/json" -X POST -d '{"usuario":"foo","senha":"bar"}' http://127.0.0.1/students/ usuario and senha are the names of the…
-
1
votes3
answers78
viewsA: Where do the HTML form data go?
The form data is sent to a computer that we normally call "server". Data processing is done inside this server. in the case of a registration, the data are saved in a database (Mysql, Postgre,…
htmlanswered Daniel Omine 19,666 -
2
votes2
answers3812
viewsA: Convert Currency Values to Decimal?
Just forgot to remove the stitch. It should be like this $estoque->valorbruto = str_replace('.', '', str_replace(',','.',substr($v1,2))); The logic here is to first convert comma per point and…