Posts by Marcelo de Andrade • 7,261 points
255 posts
-
4
votes1
answer649
viewsQ: How to undo merge keeping changes made after
The branch feature had a merge of aleatorio. How to delete this merge by keeping changes made in feature, before and after the merge?…
-
2
votes1
answer157
viewsA: Add path to fileField by clicking on image with YII framework
If you can implement javascript, you can preview using Filereader, see an example: function previewFile() { var preview = document.querySelector('img'); var file =…
-
11
votes2
answers743
viewsA: Three points in the parameter of a function in a class, what is it for?
From the version 5.6 was implemented in the arguments from the function as ..., known as Operator spread. This means that the function/method will receive a variable amount of arguments and will…
phpanswered Marcelo de Andrade 7,261 -
2
votes3
answers2732
viewsA: Return hours and minutes apart with PHP
As already answered, the class DateTime is available in versions PHP 5 >= 5.2.0 e PHP 7. What you can do to get around it is: $data1 = '2018-01-09 16:14:01'; $data2 = '2018-01-09 17:30:04';…
-
1
votes2
answers6385
viewsA: What does the HTTP Error 403.14 mean?
According to the help from MS: Why does that happen? This problem occurs because the site does not have the Search feature on Directory enabled, and the default document is not configured How can I…
-
3
votes3
answers285
viewsA: Compare and replace Intel array
You can use strftime after defining the location: setlocale(LC_TIME, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese'); date_default_timezone_set('America/Sao_Paulo'); echo ucfirst(strftime('%A',…
-
2
votes1
answer76
viewsA: PHP+JSON Webservice - Reading array
The key status is a array, to access it you must inform the index you want to get. In your case, as there is only one index, it is accessible by: $status = $retorno->data->status[0];…
-
1
votes3
answers232
viewsA: Filter array value
You can also merge the functions array_map and array_unique: $fromSQL = [ [ 'empresa' => 'abc', 'cnpj' => 72905498000142 ], [ 'empresa' => 'abc', 'cnpj' => 72905498000142 ], [ 'empresa'…
-
4
votes1
answer408
viewsQ: How to prevent the child element from activating the parent element event?
The event click configured for the element optgroup is also activated when a option is clicked. How this behavior can be avoided? $("optgroup").on("click", function() { console.log($(this));…
-
2
votes3
answers3029
viewsA: How to verify if a value exists in a multidimensional array?
The reply from @Anthraxisbr already answers, I will leave one more option: $needle = "26"; array_map(function($array) use ($needle) { return $array['user'] === $needle;}, $array);…
phpanswered Marcelo de Andrade 7,261 -
6
votes2
answers3359
viewsA: Difference between "~" tilde and "/" bar at linux prompt?
Making an Addendum to the Answer: The til character ~ is a alias directory associate home user, which can also be accessed through /, which is the starting point of directories and also known as…
-
2
votes2
answers859
viewsA: Return File Name in VBS
Yes, it is possible. See Filesystemobject: Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.GetFile("C:\Scripts\Test.txt") Wscript.Echo "File name: " &…
-
1
votes3
answers1676
viewsA: Check if there is a field inside Json
You can also pass the second parameter of json_decode as true, decoding your JSON in a array associative and use array_key_exists to check if there is a key name: $json = '{ "operacao": { "nome":…
phpanswered Marcelo de Andrade 7,261 -
2
votes2
answers210
viewsA: Difference between table, Entity and behavior
What is the difference between table, Entity and behavior in the context of the Model? While Table is responsible for accessing and representing a collection of objects, a Entity represents a unique…
-
1
votes1
answer387
viewsA: JSON returns STRING instead of ARRAY
Some points to consider: 1) No need to execute 4 querys and travel them repeatedly with while. You can make only one select and use the fetch_all of mysqli. 2) How did you not explain the intention…
-
2
votes2
answers64
viewsA: Use 'today' as default value in PHP method
As you can see in the documentation, in the topic Function arguments: The default value needs to be a constant expression, not (for example) a variable, a class member or a function call. For your…
phpanswered Marcelo de Andrade 7,261 -
4
votes1
answer905
viewsA: ERROR #1111 - Invalid use of group Function (SUM | COUNT)
The grouping functions as COUNT, SUM, AVG... among many others, should be used with grouping of data using the clause GROUP BY, and you are not using to define how will be the grouping and counting…
-
1
votes1
answer105
viewsA: Adding a Character to a column value
Concatenate by adding the text: SELECT CAST(quantidade AS NVARCHAR) + ' Tons' FROM tabela
-
2
votes3
answers112
viewsA: How to simplify the process of verifying a certain value?
Using the filter_input: filter_input(INPUT_POST, $campo, FILTER_SANITIZE_STRING) There’s a list of predefined constants for the filters. You can then simplicate a little and reduce your function…
-
0
votes2
answers37
viewsQ: To get a single element through the.filter array
Using array.map and array.filter, I select only one object from address, but his return contains a array empty-indexed. The array has the following structure: [ { "formatted_address": "275-291…
javascriptasked Marcelo de Andrade 7,261 -
1
votes1
answer121
viewsQ: Cannot find module@google/maps
I’m using the package @google/maps, installing: npm install @google/maps and npm install @types/googlemaps I made the import: import * as gmaps from '@google/maps' But I get the error Cannot find…
-
4
votes2
answers244
viewsA: Check is Curl image
You can use the function curl_getinfo that will return the contentType, from there you can use a validation for the image types you need: $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);…
-
3
votes3
answers525
viewsA: Login without differentiating between capital letters and minusculas?
Since you do not know how it is being stored, use the COLLATIONS CASE INSENSITIVE to carry out this work: $sql = "SELECT * FROM users WHERE username COLLATE utf8_general_ci = '$Name' &&…
-
0
votes2
answers167
viewsA: Tags < ? and ? > interpreted as html commentary
Likely that the Directive short_open_tag is disabled. 1) Check that it is activated: Via command line: php -i | grep short_open_tag Via file .php: phpinfo(); 2) Find the files .ini to effect change:…
-
1
votes2
answers163
viewsA: How to add items to an array correctly?
This behavior is described in the topic Objects and References of the documentation of PHP, it says: Starting with PHP 5, an object variable no longer contains itself object as value. It contains an…
-
1
votes5
answers12287
viewsA: How to perform SQL concatenation
They gave the option of CONCAT, but he was imploded in SQL SERVER 2012, is very likely to be using the 2008 and is incompatible. To make the concatenation, it must be a string. The way you are doing…
-
4
votes1
answer66
viewsA: Separate year/month
If you’re working with dates, use DateTime::createFromFormat: $date = DateTime::createFromFormat('Ym', '201705'); echo $date->format('Y/m'); See the example on ideone If it’s just one string with…
phpanswered Marcelo de Andrade 7,261 -
1
votes1
answer48
viewsA: SQL in php script
Use the exhaust of apostrophes: $sql = "SELECT CAST(REPLACE(CAST(DsXML as Nvarchar(Max)),' xmlns=\"http://www.portalfiscal.inf.br/nfe\"','') as…
-
4
votes2
answers472
viewsA: Reading data from a Json with php
If you want to get only the first occurrence, you can access the index of the first element of array: echo $jsonObj->pedidos[0]->feito_data; As the key pedidos is a array, you will need to…
phpanswered Marcelo de Andrade 7,261 -
3
votes4
answers951
viewsA: Foreach in PHP reverse process
In your example it makes no sense to use a foreach, could normally use the for decreasing: for($index = count($listagem); $index > 0; $index--) { echo $index; } And if you need to display items…
phpanswered Marcelo de Andrade 7,261 -
5
votes2
answers962
viewsA: PHP multiply hour by integer value?
The return was zero because it did not return 0:05:00? The return was zero because you’re trying to multiply strings, and the conversion of PHP will interpret only the first digit 0 of your time,…
phpanswered Marcelo de Andrade 7,261 -
2
votes3
answers1626
viewsA: Single ID generation with Mysql
You can use unique identifier generation methods based on timestamp, are they: PHP uniqid(): printf("uniqid(): %s", substr(uniqid(), -6)); MySQL UUID(): SELECT LEFT(uuid(), 6); Like you just want 6…
-
2
votes2
answers348
viewsA: Parse error: syntax error, Unexpected '' (T_ENCAPSED_AND_WHITESPACE)
You are incorrectly using string concatenations. See what you’re doing on the line: echo "<img class='nav-user-photo' src='<?php echo $_SESSION['avatar'];?>'/>"; Within the echo you are…
phpanswered Marcelo de Andrade 7,261 -
2
votes1
answer72
viewsA: PDO without JSON support
As you can see in bug tracking #70384, has been fixed in PHP-5.6, PHP-7.0 and master versions (PHP-7.1). What you can do to resolve momentarily is a CAST on the return of JSON: SELECT…
-
3
votes1
answer589
viewsA: Group arrays with same index value
Just group them together by checking a loop: $etapas = []; foreach($array as $key => $value) { $etapas[$value['etapa_num']][] = $value; } See working on ideone…
phpanswered Marcelo de Andrade 7,261 -
8
votes2
answers304
viewsA: Get the remote name
Using the command git remote -v, you will see the configured remote repositories in your local project: marcelo@marcelo-X555LF:/var/www/html/projeto$ git remote -v origin…
gitanswered Marcelo de Andrade 7,261 -
15
votes2
answers1084
viewsA: How to use Traits in PHP?
Just like the @Anderson Carlos Woss has already commented and has practically answered your questions, I will make an addendum as you can read in documentation: What are Traits? Traits are…
-
4
votes3
answers220
viewsA: What is the { } in the code below? and what is the definition for?
In PHP there is N ways of writing a string, one of them is the call Sintaxe complexa. The name is not really due to the complexity of the syntax, but rather due to complex expressions that can be…
phpanswered Marcelo de Andrade 7,261 -
2
votes3
answers860
viewsA: how to increment letters in php?
In an unorthodox and XGH: $letra = 'C'; $alfabeto = range('A', 'Z'); $proxima = $alfabeto[array_search($letra, $alfabeto) +1]; var_dump($proxima); // string(1) "D"…
-
0
votes3
answers667
viewsA: Does the PHP method have line limits?
Netbeans gives me this "warning," so why? It’s a PHP rule? According to this thread in the bug tracking of Netbeans, is just one hint which can be disabled in Editor > Hints. And no, that’s not a…
-
2
votes2
answers426
viewsA: Object Syntax Problems in Json?
I am manipulating with java for Android. I need to create an object that is the shoppingsObj and then do the following shoppingsObj.latitude[] = "" If you’re using that JSON, the valid format for…
jsonanswered Marcelo de Andrade 7,261 -
0
votes1
answer371
viewsQ: How do PULL keeping HEAD changes?
Some changes were made, commited and there was conflict in some files. If there was no commits made, would resolve as follows: git stash git pull git stash pop But with commits performed, as can be…
gitasked Marcelo de Andrade 7,261 -
0
votes3
answers2344
viewsA: List folder files with PHP
Using the SPL, you can do it this way: foreach (new DirectoryIterator('../../../../SAV-Videos/Racing-Division/') as $fileInfo) { if($fileInfo->isDot()) continue; echo $fileInfo->getFilename()…
phpanswered Marcelo de Andrade 7,261 -
12
votes4
answers2530
viewsA: What are Traffic Lights in Programming?
Semaphore, is a concept created by Dijkstra to resolve competing access conflicts to the same recourse by separate procedures. An analogy for traffic lights would be a nightclub: It contains a…
-
4
votes1
answer638
viewsA: What is the pcntl_fork function for?
I came across the function pcntl_fork. I saw that she creates a process parallel, but I don’t quite understand what she does. No, there was a misunderstanding in your interpretation. The function…
-
1
votes1
answer493
viewsA: Angular 2 and PHP
The message informs you that you are iterating on something that is not eternal. Your error is here: $games = array(); $games = array( "name" => "Grand Turismo", "category" => "PS4", "price"…
-
2
votes2
answers1288
viewsA: Turn string into integer in PHP
You can do it by making a casting using the modifiers int or integer: $string = '100'; $int = (int) $string; Or using the function intval: $string = '100'; $int = intval($string);…
-
9
votes1
answer16437
viewsA: GIT Switch branch without commiting or discarding current changes
If you want to save the changes made, you can make a git stash and you’ll see something like: $ git stash Saved working directory and index state \ "WIP on master: 049d078 added the index file" HEAD…
-
3
votes3
answers224
viewsA: remove first array from an array
Use the array_shift: $arr = [['number'], [101010100], [30303030]]; array_shift($arr); print_r($arr); Will return: Array ( [0] => Array ( [0] => 101010100 ) [1] => Array ( [0] => 30303030…
phpanswered Marcelo de Andrade 7,261 -
1
votes1
answer254
viewsA: Sum of <select> values inserted in <input>
Do not access/manipulate the DOM directly, this can cause problems of security guard. For this, use the decorator @ViewChild or a bind through the directive [(ngModel)]: html: <ion-header>…