Posts by Papa Charlie • 8,721 points
217 posts
-
4
votes2
answers350
viewsA: What is the purpose of unset as cast in PHP?
What is the purpose of this implementation? I believe you’re referring to the use (unset) $var. This form is related to the typing of the variable, as well as (int) $var, or (string) $var... the use…
-
2
votes1
answer135
viewsQ: Reading and writing problems
Assuming you have an access log, each request will create or include values in the log file. Simulating several requests via ajax, I found that there is always a problem. If you log into the browser…
-
1
votes1
answer220
viewsQ: Ajax query to display multiple content
At the moment I have some banners that are loaded via ajax, and each one makes a request to load the html. Now I’m trying to optimize these processes and decided to make a single request to load as…
-
1
votes2
answers5645
viewsA: How to compare all positions of an array in PHP
If I understand correctly, compare perfectly would compare key and value of an array. For this, you can use array_diff_assoc for compute the difference between arrays with additional index checking,…
-
2
votes2
answers1305
viewsA: Check that all values in one array are part of another
You can use array_diff to calculate the difference and consider the same or no array. Being his inputA a string, just use explode to transform into an array and compare the items into arrays. Note…
phpanswered Papa Charlie 8,721 -
6
votes7
answers59028
viewsA: Refactoring function to remove punctuation, spaces and special characters
You can use PHP to simply remove accents using iconv, case-sensitive, and conflict-free. IGNORE will ignore characters that may not have a translation. Then preg_replace will remove what is not A-Z…
-
0
votes2
answers185
viewsQ: Loop to repeat the previous keys (3, 32, 321, ...)
I’m trying to make a breadcrumb dynamic and need to make a loop to mount the link. At each loop, it needs to repeat the previous items, as in the example below the array and the output. array(…
-
5
votes3
answers494
viewsA: How to "unlock" any text at the time of "echo" and turn each word into a link
This is a tag system, usually keywords and not part of a text. They should be individual and not a phrase. $str = 'recue o código em 4 espaços'; $str = explode( ' ' , $str ); foreach( $str as…
-
5
votes1
answer108
viewsQ: How to serialize an Exception with closure
I am trying to serialize the error generated exceptions to record a log with all the information, but the problem is that some exceptions may come with a closure within the trace and fire the…
-
7
votes1
answer1900
viewsQ: Internationalization, L10n and I18N
According to the W3, with regard to L10n and I18N, I have separated the explanation below that will serve as a basis to illustrate my doubts. L10n [ source ] Generally regarded only as a synonym for…
-
8
votes1
answer1089
viewsQ: dir, html or css attribute
The attribute dir is usually omitted for languages LTR (default) and used for RTL - which are written from right to left (Arabic and related), for the purpose of changing direction, but found…
-
6
votes1
answer492
viewsQ: Problem with mcrypt function*
I am using these two functions below to encrypt and decrypt a string. I left the example as clean as possible. Function for encryption $key = '123'; $iv = md5( md5( 'key' ) );…
-
13
votes2
answers4787
viewsA: IF syntax inside an ECHO
To use if inside an echo, needs to make use of a ternary operator all between parentheses: ( (condição) ? true : false ) $id = 1; echo 'Olá ' . ( ($id === 1) ? 'id-1' : 'id-2' ); output: Ola id-1…
-
7
votes3
answers44043
viewsA: How to put icon inside input using Font Awesome?
Another option. Formatting the element lupa as a div, inserting the chart using \f002 and using the pointer indicating that there is an event - the alert is the event demonstration click. /* campo…
-
3
votes2
answers3905
viewsA: How to delete all Cookies from a Javascript page?
I believe the code below solves. var cookies = document.cookie.split(";"); var expire = new Date(); for (var i = 0; i < cookies.length; i++) { cookie = cookies[i].split("=")[0];…
-
31
votes2
answers5413
viewsQ: Work with Session without cookies to prevent session theft
When the session is started, it creates a cookie with PHPSESSID, making the ID public. Knowing that to prevent session hijacking it is best to hide the session ID from other users, then PHPSESSID…
-
2
votes2
answers196
viewsA: Solution for screen transition
use $(this).offset().top. offset() will get the element coordinates, while $(this).offset().top will pick up the distance of the element clicked in the vertical position. In the Animate you use the…
jqueryanswered Papa Charlie 8,721 -
2
votes1
answer165
viewsQ: Error log by INI and in script
I have my error handling using the functions set_error_handler, set_exception_handler, register_shutdown_function, where I debug and write the error message with detailed information and on PHP.INI…
-
4
votes1
answer75
viewsA: How to match a value before it is available?
Your problem apparently is that you are setting the variables in the wrong place as the example below - you want to use a variable that has not yet been defined. <html> <head>…
phpanswered Papa Charlie 8,721 -
3
votes2
answers1711
viewsA: Correct way to perform a dynamic UPDATE with PHP in Mysql
First of all, always ensure data validation. I’ve made a simple example that might suit you to assemble your own mini ORM. Basically it will combine the received data with the types defined to mount…
-
2
votes1
answer185
viewsA: Block PHP contact media
Users will find a way to pass on personal information. If you can’t email: [email protected], someone will change until your rule fails: papa arroba charlie ponto com, papa(a)charlie dot com...…
phpanswered Papa Charlie 8,721 -
8
votes1
answer925
viewsA: Time access restriction with php
I’m sorry, but this is gonna be more of a foot shot than a security measure. Spam zombies are end-user computers that have been compromised by malicious code in general, such as worms, bots, viruses…
-
4
votes1
answer135
viewsA: How to transform this array?
A simple way would be using implode in the array using '/' and then turning into array with explode '/'. I just played in the ideone. $array = array( 0 => 'APARTAMENTO', 1 => 'CASA', 2 =>…
-
11
votes3
answers1122
viewsA: Is it possible to manipulate PHP errors via code?
Note that depending on the error, the execution of the script will be stopped. If at any time DB gave stopped and generated an error, you will not be able to generate the LOG, so usually the Logs…
-
1
votes1
answer189
viewsA: Problem with the variable error?
I edited it into your code: require_once( '../../sllapsocial/classes/DB.class.php' ); if( $_SERVER['REQUEST_METHOD'] == 'POST' ) { $nome =$_POST['nome']; $sobrenome = $_POST['sobrenome']; $email =…
phpanswered Papa Charlie 8,721 -
2
votes2
answers253
viewsQ: Replace in large string or split loop
I have a multidimensional array with some routes and need to do the conversion of some elements defined as: (alpha), (int), (id), etc. As it is an array, at the moment I use a loop to do the…
-
1
votes3
answers545
viewsA: autoload in classes using mvc
Your question and answer do not seem to compose with OOP code, if you can enlarge the example I can give wider answer, but for now, I think this example can judge. You can create a simple autoload.…
-
1
votes2
answers507
viewsA: Difficulty with rewriting friendly Urls
Basically you’ll do the HTACCESS send to PHP to route the URL. No need to do querystring as PHP will use REQUEST_URI to route the request. .HTACCESS RewriteEngine On RewriteCond %{REQUEST_FILENAME}…
-
1
votes2
answers845
viewsA: I can’t get the value of an input to compare within a _Construct
Reply concerning the error: Notice: Undefined variable: type Note that the variable $tipo is only being defined if $_POST['register_tipo'] be sent. You can use the form below and check if the field…
phpanswered Papa Charlie 8,721 -
4
votes3
answers381
viewsA: PHP takes data from the SPLIT array
You can use an ER, see an example on ideone. $string = '/Date(770094000000-0300)/'; preg_match( "/([0-9]+)-([0-9]+)/" , $string , $match ); print_r( $match ); // output array ( [0] =>…
phpanswered Papa Charlie 8,721 -
2
votes3
answers9448
viewsA: Add and remove class
I made a simpler example of what you want, is in jsfiddle, basically by clicking the button, you hide the descriptions and apply the visibility in the corresponding elements - description and image.…
-
1
votes2
answers3727
viewsA: Retrieve content between custom tags using Regex
1) If you intend to use ONLY the content of the tag, you can use the ER below, in case it removes everything between <>: $conteudo = '<:item>Conteúdo</item>'; print_r(…
-
16
votes12
answers5446
viewsA: How to remove accent in upload with php?
Simply remove accents: $file = "ação-íaaa.jpg"; $file = iconv('UTF-8', 'ASCII//TRANSLIT', $file); echo "{$file} <br>"; Output: acao-iaaa.jpg Example available on ideone…
phpanswered Papa Charlie 8,721 -
0
votes2
answers1483
viewsA: How should I subtract arrays
Based on the @Bacco example, I will propose another way using array_merge_recursive. Basically it will combine the 2 arrays and generate an array of 2 keys when there is combination, then a loop…
-
1
votes1
answer439
viewsA: Undefined variable in Codeigniter
Fatal error: Call to a Member Function result() on a non-object in C: Program Files (x86) Easyphp-5.3.8.0 www marcar_query application views listar.php on line 21 In his view you use $consulta->…
-
4
votes1
answer512
viewsA: Notice: Undefined variable: name in C: wamp
PHP is responding that the variable was not defined (Undefined variable). Use isset to check if the variable was created. if( isset( $nome ) ) { if( $nome == '' OR strlen( $nome ) < 4 ) { echo…
phpanswered Papa Charlie 8,721 -
2
votes1
answer74
viewsA: How to organize matrix
Array-diff, returns an array containing all array1 entries that are not present in any of the other arrays. Array-diff will return to KEY and VALUE, for this reason you do not receive an array with…
-
6
votes1
answer296
viewsQ: Differences between traits and namespace for loading
Using namespace the file is uploaded at the time when some method is used say, If you do not invoke anything from class the file will not be loaded. use World; class Hello { World::say() } Using…
-
5
votes2
answers1472
viewsA: Discontinuation of the <center> tag
. The tag should be avoided because it has been disapproved since HTML version 4. [source] . Not only is HTML5 not supported. [source] <center> is obsolete but its effect can be achieved using…
htmlanswered Papa Charlie 8,721 -
1
votes3
answers160
viewsA: bg-image internationalization by CSS
In PHP use translation packages for each language: language/ pt.php en.php es.php You can create a CSS only with the images for each language. Separate the images into a css-language.css and load…
-
3
votes1
answer6540
viewsA: CSS animation of input and output element when scrolling on page
In your case, apply the transition in div box, limit the entry and exit effect. To make the move would need to apply removeClass but would lose formatting. Another problem is that when collecting…
-
8
votes4
answers1051
viewsA: How to do if and Else of between 2 variables with output in a third?
I’m not sure that’s what you want. You need to know what kind are the $ip1 and $ip2 - if they are bool or if they are real ips. Tell me to adjust the question. Option 1: if( isset( $ip1 ) ){ $ip3 =…
-
2
votes2
answers12400
viewsA: Modal window with database contents
I created a jsfiddle very basic. The loop will create a hidden div to receive the information and the modal will use it and accept formatting. I hope it serves as a basis for you to assemble your…
-
3
votes3
answers181
viewsA: I have sets of variables storing different settings. How to use a specific set depending on the occasion?
You can create individual files for each connection, u as @bfavaretto suggested, create an array containing the indexes: #pasta/config/database.php return array( 'DB1' => array( 's_ipserver'…
phpanswered Papa Charlie 8,721 -
5
votes1
answer320
viewsA: Mysqli SUM query does not return result
Lacked use fetch: $sql = 'SELECT SUM(size) as soma, porta FROM `'.$this->options['db_table'].'` WHERE `porta`=?'; $query = $db->prepare($sql); $query->bind_param('s', $file->porta);…
-
17
votes1
answer1380
viewsA: Is it good practice not to close the . php file with ? > after an XHR call made from a . html file?
PHP DOC The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is useful when using include or require, so unwanted whitespace will not appear at the end of…
-
10
votes2
answers664
viewsQ: Redirection: Location vs Refresh
When to use Location and Refresh to redirect. header( "Location: www.dominio.com" , TRUE , 302 ) header( "Refresh:5; url=www.dominio.com" , TRUE , 302 ) Both options produce the same result:…
-
1
votes1
answer932
viewsA: Sum or subtract a field’s value in a database with Codeigniter
See an example of DOC $data = array( 'title' => $title , 'name' => $name ); $this-> db-> where( 'id' , $id ); $this-> db-> update( 'mytable' , $data ); Your query can be written as…
codeigniteranswered Papa Charlie 8,721 -
3
votes2
answers1264
viewsA: Measure time the user is logged in to the system
From the description you gave, I imagine you do not save session, much less cookie, and leaving the site should log in again. So I present a simple example of 2 tables. USERS ID | NOME | SENHA |…
-
1
votes2
answers724
viewsA: Popular input with data from the same table via dropdown
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function() { $('#produto').change(function() { $('#recebe').val( $(…