Posts by Daniel Omine • 19,666 points
581 posts
-
2
votes7
answers1134
viewsA: Select a file by name in PHP
Using function replace() $str = '20160111_ALGUMA_COISA.txt'; echo substr($str, 0, 8); // retorna '20160111' The value zero is the starting point of the string. The value 8 is the end point where the…
-
2
votes2
answers201
viewsA: Interface with the same class name
In OOP, an interface is a class with a specific flag that identifies it as an interface type. PHP interprets it that way, as if an interface were a class. Hence the error. An interface must have a…
-
5
votes5
answers7178
viewsA: What is the advantage of using recursive functions?
Who does not experiment in practice ends up not understanding the theory. So it is always good to show a practical example of use in the "real world". A basic tip to know when to deploy is, when you…
-
0
votes3
answers786
viewsA: How to take several arrays with 1 single index and put in a single array?
Loop by taking the values of the multidimensional array and throwing them into a simple array. In the example below override the original array itself: $arr = array(array('a'), array('b'),…
-
1
votes2
answers823
viewsA: Adding the column of a PHP table
Start variable with zero value. Inside the loop, increment the value of each sum. Just don’t confuse subtotal (total unit) with the total general. Note that more Row has been created…
-
1
votes2
answers867
viewsA: What is the difference between the terms "extension" and "component"?
In short, a component adds more functionality to something already existing. An extension adds new functionalities that do not exist or even exist already, such functionalities are like an…
terminologyanswered Daniel Omine 19,666 -
0
votes3
answers6054
viewsA: How to concatenate HTML within PHP
This looks like an HTML being generated by Javascript. So it’s a little different than what you ask for. To make PHP write this, you have to choose which type of delimiter to use in PHP and then set…
-
1
votes2
answers758
viewsA: Php server check
if (stripos(php_uname('s'), 'win') === 0) { echo 'windows'; } else { echo 'other, probably *unix family'; } or if (DIRECTORY_SEPARATOR == '\\') { echo 'windows'; } else { echo 'other, probably *unix…
phpanswered Daniel Omine 19,666 -
1
votes2
answers89
viewsA: Mysql, help to understand data export
What happens is that the second form generates a consistency of data. The command CREATE TABLE IF NOT EXISTS create a new table if there is no. So, at this point you can create a data conflict if…
-
1
votes3
answers410
viewsA: Send variables to PHP via Ajax - undefined variables
In the archive sessUser.php, is rescuing the $_POST and assigning variables outside the scope of the function inclusao(). Move variables into the function: <?php function inclusao() { $servico =…
-
4
votes1
answer367
viewsA: What is the best way to accentuate words in . js files?
Set up your text editor (Notepad++, sublime, etc.) to save edits as UTF-8 or the charset you find most suitable for your case. It is recommended to use a multibyte character set such as UTF-8 (No…
-
7
votes4
answers142
viewsA: Does calling dozens of classes in a system noticeably influence the performance of the application?
Speaking more of the same, it makes no difference. The explanation is in the other answers. A practical point to be aware of is how these classes are loaded. You will probably want to use an…
-
1
votes2
answers268
viewsA: How do I update PHP 7.0.0RC1 to version 7.0 already released in centos?
If you have YUM, I recommend the repository Webtatic Before installing anything, always make sure there is no more installation. yum list installed | grep php | cut -d' ' -F1 In bold, search…
-
2
votes3
answers2082
viewsA: After "apt-get dist-upgrade" command, PHP 7 was installed. How to go back to 5?
Before installing, always check for existing packages. This will return a list of packages containing the word PHP, if any: >dpkg --get-selections | php Remove packages that need to be removed.…
-
2
votes2
answers410
viewsA: How to use sprintf to mount an SQL query?
First of all, sprintf() has nothing to do with mysqli(). Let’s cut to the chase. In this passage: $rs = $mysqli->query(sprintf("INSERT INTO perguntas (chave, nome, email, idade, estado_civil,…
-
4
votes2
answers7415
viewsA: Why use error_reporting with display_errors and display_startup_errors?
A complement to the existing answer, Depending on the environment, error_reporting(); or ini_set('display_errors', ..); can be ignored when invoked at runtime. To put it more simply, there are…
-
4
votes3
answers16275
viewsA: How to send a data to another PHP page by URL?
Practical example by the GET method This link will send the parameter by the GET method <a href="test.php?tmpString=Teste">link teste</a> To rescue the "tmpString" parameter on the…
-
1
votes3
answers544
viewsA: Open php file in ascending order
Save file names to an array and use the function natcasesort() to organize them alphabetically. Teaching example: $base = __DIR__.DIRECTORY_SEPARATOR; $dir = dir($base); while (false !== ($e =…
-
0
votes2
answers452
viewsA: Logic PHP: how to build this looping (for, while, foreach)?
An interesting way to do using recursiveness with anonymous function: $arr['linha 1']['coluna 1'] = 11; $arr['linha 1']['coluna 2'] = 12; $arr['linha 2']['coluna 1'] = 21; $arr['linha 2']['coluna…
-
2
votes1
answer98
viewsA: How to insert an instruction into the array only if it is true?
Checks that the value is not empty. If empty, arrow is null. Example of how to add to index filter array $dados: 'filter' => array( 'categoria' => ((!empty($values))? array($values) : null) ),…
-
3
votes1
answer1698
viewsA: CSS and Javascript files do not load when I use Amigavel URL
The simplest way to resolve static links is to define the HTML tag <base href="http://endereço.base-do-seu.site/"> Another way is to set the absolute path on all links (href, src) or the…
-
3
votes3
answers825
viewsA: Make the page refresh and the message appear next
Save a cookie flag and check if it exists. This technique is also useful to prevent duplicate submissions. However, we will not address here the rules for blocking duplicate sending. Example of…
-
2
votes2
answers94
viewsA: With this rule below, how do I show the first and last user name in the database?
Example using the array functions: $str = 'José Alberto da Silva Nogueira'; $arr = explode(' ', $str); echo ((count($arr) < 2)? $str : current($arr).' '.end($arr)); Example using string…
-
1
votes3
answers1452
viewsA: URL problem with Toolbar /
Define the directive Rewritebase RewriteBase / Modify the Slash trailing rule: RewriteRule ^(.*)/$ $1 [L,R=301] Just removed the bar on /$1 because we have already defined the RewriteBase Note:…
-
2
votes3
answers785
viewsA: How to treat the logged-in user in a MVC system?
I suggest implementing as a plugin or "hook". I have been developing PHP frameworks for many years. In the penultimate version, built in 2009, I implemented user/login permissions reading within the…
-
13
votes4
answers23430
viewsA: How to treat accentuation in. bat files?
Perform two simple steps: Save the file . bat with UTF-8 charset Specify the charset inside the file . bat using the command chcp (Change Code Page). For UTF-8, the code is 65001 Example foo bat.…
-
2
votes1
answer247
viewsA: HTACCESS - Directory deletion condition
Add a. htaccess file to the /admin folder/ In this file, just put the command to disable mod_rewrite: RewriteEngine off
-
4
votes3
answers1209
viewsA: Get the name of the Image in the URL
An example using the method lastIndexOf() url = '/data/data/com.intel.appx.IZICondominios.xwalk15/files/_pictures/picture_006.jpg'; var filename = url.substring(url.lastIndexOf('/')+1);…
-
0
votes3
answers247
viewsA: Switch Result
I got here because of a duplicate: Switch with several POST I’m going to share something I didn’t see in any response or comment. It is a more flexible technique that allows conditional structures:…
-
2
votes3
answers252
viewsA: Use of preg_replace invalidates password with SHA1
There is no need to filter the string as it will be converted to a hash. The hash will convert everything, including escape characters that would allow sql injections or any other type of…
-
1
votes2
answers792
viewsA: Format date and monetary value to save to database
Whereas the original date is in the dd-mm-yy format (2-digit day, month and year), the year of which is within the 21st century (2001~2100) and, also considering that it is using Mysql database, the…
-
0
votes4
answers582
viewsA: How do I SELECT then INSERT
Suggestion for correction if(isset($_POST['submit'])){ $query = $conexao->prepare("SELECT id_mark, id_user FROM tb_comment WHERE id_mark=:post_id AND id_user=:idLogged");…
-
4
votes4
answers4957
viewsA: Call static class method by static variable
The error is triggered due to conflict in the use of the scope resolution operator (::) In the second operator (::), the compiler understands that it is calling a method from a non-existent…
-
2
votes1
answer423
viewsA: Can denying access to a mod_rewrite folder be unsafe?
Normally the verification technique of a constant is used. So as you showed it is very interesting because it leaves the code clean and free from the gambiarra of constant technique. The portability…
-
3
votes1
answer37
viewsA: Error in jquery return
I think the problem is due to an error that triggers the debugger of the framework you are using. With this, the debugger of this framework prints the information, which is a kind of backtrace of…
-
0
votes2
answers1756
viewsA: Replication between Mysql and Sqlite (E vice versa)
There is no way to replicate directly. You need to create a Webservice/API to communicate. This is a little complex because you need to be careful with the version control of the data. There is a…
-
3
votes3
answers3064
viewsA: Count of occurrences in a String
See the roles of the PHP.JS project It is a project that translates functions from PHP to Javascript. In PHP there is a function count_chars, which is translated into Javascript on the project…
javascriptanswered Daniel Omine 19,666 -
4
votes3
answers2136
viewsA: Error 500 Internal Server Error
The "500 Internal Server Error" message usually indicates error coming from the web server. Usually from Apache. A common cause is some error in htaccess. To verify the error, read the server error…
-
2
votes2
answers279
viewsA: .htaccess wildcard subdomain pointing to directory + hash
This rule redirects all subdomains: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.foo\.bar$ RewriteRule ^/?(.*)$ http://www.foo.bar/$1 [R=301,L] Based on that, your case would look like this…
-
1
votes4
answers268
viewsA: BETWEEN demands arguments in ascending order? Why?
It’s just a pattern. But I believe it was so standardized because the reverse would give the same result. It would be redundant and generate process costs when implementing in the compiler which…
-
2
votes2
answers162
viewsA: How to make URL friendly without apache mod_rewrite?
It is a valid technique for cases where URL rewriting is not available, either by Apache, Nginx, IIS or any other server. This is called a "false friendly url". Or "fake mod_rewrite". Finally, there…
-
2
votes3
answers1027
viewsA: $GLOBALS to store settings?
There is no guideline in which say how we should design the system. Therefore, we cannot say that it is right or wrong to store such data in the variable $GLOBALS. However, there is a concern…
-
2
votes2
answers1145
viewsA: How to assign a different value to the variable in each loop?
Example with a continuous rotation $arr = array(1, 2, 3, 4); //aqui seriam as 4 cores. $data = range(1, 100); // isso aqui simula os dados onde o laço de repetição percorre. foreach ($data as $v) {…
phpanswered Daniel Omine 19,666 -
1
votes2
answers343
viewsA: Error passing PHP Array to Angularjs by JSON
I just removed redundancies and nonsense: <?php header('Content-Type:text/html;charset=UTF-8'); include("../class/conexao.class.php"); $myData = json_decode($_POST['myData'], true); $userid =…
-
1
votes2
answers275
viewsA: Import PHP files through the URL instead of the disk path
Standardize with the use of autoloader in the PSR-4 standard: http://www.php-fig.org/psr/psr-4/ For example, the concept idea is to use namespace to facilitate route assembly. The namespace feature…
-
6
votes2
answers855
viewsA: What is the use of declaring variables through braces?
Brackets are used in the variable declaration when there is a need to use placeholder names or characters that could cause syntax error in a normal declaration. It is also used to invoke variables…
-
1
votes1
answer490
viewsA: How to block iframes in input
The moment you receive the input value entered by the user, just select the value. Example: $str = '<iframe width="560" height="315" src="https://www.youtube.com/" frameborder="0"…
phpanswered Daniel Omine 19,666 -
4
votes3
answers907
viewsA: Sum array in javascript currency
Remove the dot character (.) Replace the semicolon character (,) with a dot (.) str = '1.568,78901'; str = str.replace(/[.]/g, ''); str = str.replace(/[,]/g, '.'); console.log(str);…
-
3
votes1
answer718
viewsA: Run two services in the same domain on separate ports
In the documentation there are examples of how to configure: http://nginx.org/en/docs/http/server_names.html Configuration example: server { listen 80; server_name foo.bar www.foo.bar; root…
nginxanswered Daniel Omine 19,666 -
4
votes1
answer4116
viewsA: use excel spreadsheet to fill web form
The simplest and cheapest way can be just by exporting to a CSV format or any other format that is easy to import through the web application. You will only have the job of creating the data…