Posts by Daniel Omine • 19,666 points
581 posts
-
1
votes2
answers188
viewsA: Is there a difference in performance between "new" and "clone" in PHP?
The question you must ask yourself is whether you need to instantiate so many classes. Modify to clone() will not bring visible advantage as it would be a microtimization and without guarantee that…
-
5
votes2
answers397
viewsA: MYSQL - Check if PK exists if it does UPDATE if it does not exist
It may be interesting REPLACE INTO It works like INSERT only when it finds a PK or Uniquekey, the old line is removed and then the new one is inserted.…
mysqlanswered Daniel Omine 19,666 -
0
votes2
answers161
viewsA: How to give Submit in the data of a dynamically generated form?
Suggested solution Just after this excerpt, close the tag </form> <a class="btn btn-primary" href="javascript:void(0)" id="addInput"> <span class="glyphicon glyphicon-plus"…
-
1
votes2
answers212
viewsA: How to manipulate the string coming from a . reg file exported from regedit?
The idea is to simplify by going straight to the point, making an explode() grosserio to transform each line into an array item. Then read the relevant index. Since the first two are mere noises,…
phpanswered Daniel Omine 19,666 -
4
votes1
answer388
viewsA: How to write and read windows registry data with php?
To write to the Windows registry, run the command reg import <?php exec('reg import c:\arquivo.reg'); To read a Windows record, run the command reg export <?php // Exporta o registro para um…
phpanswered Daniel Omine 19,666 -
2
votes1
answer5051
viewsA: How do I fix the php ERR_CACHE_MISS?
This has no relation to PHP. It is the default behavior of the browser. When a page submits data by the POST method, this data needs to be submitted again by going back to navigation. If the…
-
1
votes1
answer822
viewsA: How to update image cache via PHP
The most guaranteed way is to add a new parameter to the image link. Example: imagem.jpg?20170724. If I change it tomorrow it would look something like imagem.jpg?20170725. You can try all these…
-
1
votes2
answers94
viewsA: How to organize multi-level MVC application
A controller can have N views. If you think a view is best for each case (normal user and admin), it’s no problem. But it doesn’t matter if you use a single view with conditional or multiple views.…
-
0
votes2
answers315
viewsA: Fill missing numbers from a sequence
/* Array de teste. Existe apenas 1, 4, 8 e 11 */ $result = array( 0 => (object)array( 'hora' => 1, 'views' => 3 ), 1 => (object)array( 'hora' => 4, 'views' => 3 ), 2 =>…
-
5
votes1
answer86
viewsA: How to handle ids with php?
After that line $id = $_GET['id']; Take a treatment of the amount received before proceeding with other actions. Normally the ID is numerical, so considering it to be a numerical value, Sanitize and…
-
1
votes3
answers1607
viewsA: Schedule php script in windows
No need to run through the browser. Run PHP by command line. In the task scheduler specify the same command you would use for cmd (prompt) c:\local\do\compilador\php.exe -f c:\local\do\script.php Be…
-
0
votes2
answers89
viewsA: Doubts with value of selects
In the original script of the question is already very close to a solution that I will suggest. Because the onchange event is already registered. When the user chooses the option, assign the option…
-
2
votes2
answers346
viewsA: Assign function to variable?
I did some cleaning, removing unnecessary things. What you need is just to use the return instead of echo, within the function. Refer to the manual:…
phpanswered Daniel Omine 19,666 -
2
votes2
answers640
viewsA: Retrieve text from <li> and move to PHP
The hidden element with "class=btn-select-input" selector receives the chosen value. <input type="hidden" class="btn-select-input" id="" name="" value="" /> The Javascript snippet that assigns…
-
1
votes2
answers1193
viewsA: Avoid notice in PHP display_error
The problem is the lack of quotes to delimit strings. define(siteprot, $_SERVER[HTTPS] ? 'https://' : 'http://'); define(sitehost, $_SERVER[HTTP_HOST]); define(siteuri, $_SERVER[REQUEST_U... It…
phpanswered Daniel Omine 19,666 -
0
votes4
answers29938
viewsA: Regular expression to accept only numbers and a ","
/** 全角数字・全角アルファベットを半角に変換 Convert zenkaku to hankaku ie: japanese number like 012, will be converted to 012. */ function ZenKakuToHankaku(str) { if (str == "") { return ""; } //16進数の場合 (0xFEE0…
javascriptanswered Daniel Omine 19,666 -
1
votes3
answers139
viewsA: Get the last "word" of a PATH with different URL formats
Using the function parse_url() can facilitate the work. <?php $arr = array( 'http://localhost/', 'https://localhost/', 'http://localhost', 'https://localhost', 'http://sub.localhost/',…
phpanswered Daniel Omine 19,666 -
2
votes1
answer70
viewsA: How to change the host address where requests "src" and "href" go?
The right term would be "turn relative url into absolute url". Check if the URL has http at the beginning of the string. If it does not have a relative URL. $domain = 'https://dominio/'; $url =…
-
18
votes2
answers463
viewsA: What’s a loose comparison?
The comparison loose does not compare the type as in the comparison rigid. $x = 1 $y = "1" $x is different from $y because although they have the same value, the first is a variable to type int and…
-
0
votes2
answers128
viewsA: URL form sending nomenclature
There is no "best way" because this is already the correct format. This is called "encoded url". In the backend, PHP for example, decode with the function urldecode() if necessary.…
urlanswered Daniel Omine 19,666 -
5
votes1
answer1360
viewsA: Start command with special characters (CMD)
Delimite the password with double quote. Double quote exhaust with another double quote Example for the password a.qui<>_a_s'enha_";)_ pwd:"a.qui<>_a_s'enha_"";)_"…
cmdanswered Daniel Omine 19,666 -
2
votes2
answers97
viewsA: Best practice for deleted data
One technique I developed and it’s nothing new, is to move the data to another table. Normally I duplicate almost all tables and for some I still create a third auxiliary table. Example, a product…
databaseanswered Daniel Omine 19,666 -
1
votes3
answers67
viewsA: How to define the value of a variable from a function?
Inside the function, use: window[variable] = value; Example function setVariableValue(variable, value) { window[variable] = value; } To set the value test = 30; console.log(test); // imprime 30…
-
0
votes3
answers165
viewsA: Do not echo an empty Row IS NOT NULL
The appropriate way, via PHP, is as answered @Brunorigolon. You can also resolve only in the SQL query. The problem is that NULL is different from empty. and probably the fields are not as NULL but…
phpanswered Daniel Omine 19,666 -
3
votes5
answers1745
viewsA: Console utilities.log()
It is a Javascript resource used for debugging (debugging). It generates logs that can be consulted in the browser console. In Google Chrome, press CTRL+SHIFT+I, choose "console". This is where the…
javascriptanswered Daniel Omine 19,666 -
1
votes2
answers1654
viewsA: Fill input with Function javascript result
Replaces Alert by field value assignment: <input ID="txCNPJ_cad_emp" name="cnpj" class="form-control" placeholder="Digite o CNPJ" onkeyup="FormataCnpj(this,event)"…
javascriptanswered Daniel Omine 19,666 -
2
votes1
answer152
viewsA: Index site page as topics in google
The name of this is "sitelinks". Who determines what and how will be displayed on the google result page is the mechanism itself. You cannot determine which links should appear. You can just ask for…
-
2
votes1
answer567
viewsA: Syntax error error, Unexpected '[' in
It’s the same problem with that other question you asked yourself: Syntax error, Unexpected T_OBJECT_OPERATOR This system you are trying to use was probably written by someone who was not careful to…
phpanswered Daniel Omine 19,666 -
2
votes1
answer2157
viewsA: Syntax error, Unexpected T_OBJECT_OPERATOR
Along those lines, $this->autos = (new ModelAuto)->get_all_busca($busca); Fix it that way $c = new ModelAuto; $this->autos = $c->get_all_busca($busca); Moreover, to avoid redundancy,…
phpanswered Daniel Omine 19,666 -
1
votes1
answer395
viewsA: Linux commands through Laravel
You can do it using the "process" component (Laravel 5) http://symfony.com/doc/current/components/process.html You can also invoke PHP’s own functions http://php.net/manual/en/function.exec.php,…
-
0
votes1
answer700
viewsA: Association between classes with PHP
On the line pointed by error . "Fornecedor: {$Produto->Fornecedor->getRazao()}" Fix it that way: . "Fornecedor: {$Produto->getFornecedor()->getRazao()}"; Upshot:…
-
1
votes1
answer438
viewsA: How to include a PHP variable inside a saved text in Mysql
This is a template. Just replace "tags" with variables. Example: $texto_db = 'Número do contrato: {contrato} Nome: {nome} etc...'; echo str_replace( array( '{contrato}', '{nome}'), array(…
-
1
votes1
answer251
viewsA: Is it possible to generate 2 identical sequences with md5 if the same base is used?
The MD5 string will always be the same for the same base string. Example: 1 -> c4ca4238a0b923820dcc509a6f75849b abc -> 900150983cd24fb0d6963f7d28e17f72 As described in the question, the logic…
-
0
votes4
answers1139
viewsA: Separating columns from a multidimensional array
From PHP 5.5.0 there is the function array_column() Example of use, similar to your case: $arr = array( array('74','69'), array('45','1'), array('5','2'), array('88','3') ); //Pega todos do primeiro…
phpanswered Daniel Omine 19,666 -
3
votes1
answer844
viewsA: How to save array to db?
Example of how to mount an Insert with multiple values instead of generating an Insert for each loop repetition. Comments of what makes the script are embedded in the code. Note that there is no…
-
1
votes2
answers125
viewsA: POST crashes the script and does not execute the code after form Ubmit
If you pass through it is because the conditional does not return true. Besides, it’s a very weak, inconsistent, redundant parole. It is inconsistent because it does not validate the input. It only…
-
1
votes1
answer79
viewsA: Variable type verification problem INT
Sanitization usually comes before validation. What you set up does the opposite. It tries to validate and then sanitize but since it should not be receiving the appropriate type, it always falls in…
phpanswered Daniel Omine 19,666 -
2
votes1
answer33
viewsA: Class incompatible with the interface
Interface is like a "contract". The interface defines what the MUST class has. In the method create() class Filme{}, there is an additional parameter ($download) relative to the same method defined…
-
0
votes1
answer415
viewsA: how to install imagemagick on Magic ( Xampp)
If you have Homebrew, run it in the command console: Install imagemagick if not installed: brew install imagemagick Installing imagemagick DOES NOT include the library for PHP. Therefore, install…
-
1
votes3
answers363
viewsA: Problem with Between in Mysql?
The columns must be of the datetime. In case you want to keep the current type (varchar), will have to do a cast. I suggest to use in conjunction with the function UNIX_TIMESTAMP(). Below, just the…
-
3
votes1
answer467
viewsA: Load Video by PHP (only part)
One suggestion is to generate a new video containing only the snippet that matters. In the example below was used the ffmpeg: // Tempo em segundos $ini = 540; // início (9 minutos) $end = 600; //…
phpanswered Daniel Omine 19,666 -
2
votes1
answer445
viewsA: Create email account with PHP through CPANEL
The CPANEL documentation guides you to use the UAPI: https://documentation.cpanel.net/display/SDK/Guide+to+UAPI Supported version: 11.42 or higher To create an email account, I’ll show you an…
phpanswered Daniel Omine 19,666 -
3
votes5
answers1493
viewsA: How to create a function to validate time in PHP
An option with sanitization. Routine sanitizes user input by removing anything that is not a number, but preserves the character :. It also converts full-width numeric characters (zenkaku) and…
phpanswered Daniel Omine 19,666 -
2
votes1
answer117
viewsA: Undefined offset in repetition loop in PHP
The number 100 indicates to the webservice the limit and not the exact amount that should return. Therefore, you should not expect that it will always return 100 results. To resolve, use the repeat…
-
3
votes4
answers2070
viewsA: PHP, how do I stop when the number after . is 0 is hidden?
Formatting with float type When the variable does not have the value inside quotes, the Zeros on the right are omitted "automatically" $n = 100.00; echo $n; // retorna 100 $n = 100.30; echo $n; //…
phpanswered Daniel Omine 19,666 -
1
votes2
answers1970
viewsA: Accentuation problem when migrating to PHP7
Very likely there is a conflict with the configuration of the environment. Because according to what you reported, in the previous environment everything was working. Moreover, PHP7 does not bring…
-
0
votes1
answer35
viewsA: Take data from option
The form will submit only the values. To get the "option" type elements, you will have to create some logic involving avaScript or a gambiarra in the "value" attribute of the element itself. A…
phpanswered Daniel Omine 19,666 -
1
votes2
answers241
viewsA: Difficulty using ob_start(); ob_end_flush(); and their similar?
It’s unclear where the problem is. Apparently a single error triggered the following. Strict Standards: Only variables should be passed by reference The error points to classes/Site.class.php in 214…
-
1
votes1
answer869
viewsA: Is it possible to configure the display errors in . htaccess?
It is possible as long as the environment (server) allows access to such settings. There is not much to say about what works or not because who can answer is the support of the hosting service.…
-
2
votes3
answers1974
viewsA: How to add more products?
Define a multidimensional array: $_SESSION['cart']['items'] = array( 'id' => 5, // código do produto 'title' => 'produto teste', // título/nome do produto 'selling_price' => 10.00 // preço…
phpanswered Daniel Omine 19,666