Posts by Papa Charlie • 8,721 points
217 posts
- 
		1 votes4 answers97 viewsA: Find a ( string ) value in a PHP arrayYou can format this array to access the keys directly. The way your values are you will still have to format the values. $dadosCli1 = array("cep:'000000'", "cidade: 'sao paulo'", "rg:… 
- 
		0 votes1 answer131 viewsA: Update the status of multiple ids at the same time Mysqli php mvcIt’s not very clear, but if I understand correctly, you can use find_in_set to update all ids without having to loop. update `TABELA` set status = 1 where find_in_set( cast( id as char ) , ? ) The… 
- 
		0 votes1 answer383 viewsA: How to send data via form to php file and return the result in an html fieldIf the question is as I understand it, you can use preventDefault to prevent the page from being submitted and run only on JS. $(document).on('click', '.submit', function( e ){ e.preventDefault();… 
- 
		1 votes1 answer104 viewsA: Configuration file and/or Constants, when to use?I don’t usually use that kind of constant define( 'FOO' , 'foo' ) just for using a class to work with configuration files. At most I use constant in classes because nothing interferes with the… 
- 
		7 votes3 answers3255 viewsQ: Wrong daylight saving timeI’m having a problem regarding daylight savings time... actually cell phones, street clocks, my pc also set the clock forward... Daylight saving time usually starts in October. But, not to coincide… 
- 
		1 votes3 answers89 viewsA: OFFSET next to COUNT(*) returns nothing?One option would be to make 2 queries, using sql_calc_found_rows and FOUND_ROWS() to pick up the total of records, as per the DOC of MYSQL. SELECT sql_calc_found_rows * FROM noticias ORDER BY… 
- 
		0 votes2 answers98 viewsA: Return n last record of a JSON file in phpTo use a portion of an array, just use array_splice. $input = array( "vermelho" , "verde" , "azul" , "amarelo" , "preto" , "cinza" ); array_splice( $input , 0 , -5 ); print_r( $input ); output Array… 
- 
		0 votes2 answers958 viewsQ: Websocket on localhost does not establish connectionI’m testing WebSocket turning at the door 80, I’ve already disabled the SSL, but I’m not getting results... javascript var ws = new WebSocket('ws://localhost:80/socket2.php'); An example I have… 
- 
		0 votes1 answer24 viewsQ: Replace no `contenteditable` does not play the end pro pointerI’m trying to replace contenteditable, it replaces but does not play the pointer pro end, always keeps at the beginning. I did not know contenteditable yet and did not find anything 'simple' that… 
- 
		5 votes1 answer81 viewsA: Find string character position and remove itYou do not need to use a function to remove zero from the first position. You can type using int. $mes = "08"; // string(2) "08" $mes = "10"; // string(2) "10" $mes = "12"; // string(2) "12" $mes =… 
- 
		1 votes1 answer68 viewsA: How to rewrite apache URL with variable and then use other variables in PHP?Apparently the flag is missing QSA en route. RewriteRule ^teste/([a-z]+)$ settings/php/teste.php?lib=$1 [QSA] See the DOC: When the Replacement URI contains a query string, the default behavior of… 
- 
		4 votes1 answer72 viewsQ: PDO without JSON supportI need to return a line in JSON, but the PDO does not seem to give full support to operations. Always the error message type 245. PDO::prepare(): Unknown type 245 sent by the server. Please send a… 
- 
		4 votes1 answer56 viewsQ: Content with code points (Entity) or Unicode charactersOn the website w3schools has the reference of all characters - specials, symbols, alphanumerics. I did not understand the purpose of having this representation of characters. In the example below… 
- 
		1 votes3 answers63 viewsQ: Reorder variables by throwing the blanks to the endI intend to play to the end of the list the variables that are null. This is part of the composition of the elements of view, are blocks that can come empty, and I want to avoid having to compare… phpasked Papa Charlie 8,721
- 
		0 votes2 answers1693 viewsA: Make PHP show sum and multiplicationTo use as you wish - new Calculadora(5,8); obj->multiplicar(); - need to create a constructor. See ideone. class Calculadora { public function __construct($num1, $num2){ $this-> num1 = $num1;… phpanswered Papa Charlie 8,721
- 
		1 votes1 answer54 viewsA: Check if an array has empty valuesIt wasn’t very clear from the example you gave, but you can make a comparison by counting the received array with the 'filtered' array without the empty indices, just use array_filter as in the… phpanswered Papa Charlie 8,721
- 
		1 votes2 answers873 viewsA: View weekdays in order with PHP$a = [ 1 => 'seg' , 2 => 'ter' , 3 => 'qua' , 4 => 'qui' , 5 => 'sex' , 6 => 'sab' , 7 => 'dom' ]; $b[] = array_slice($a, date('N') - 1 ); $b[] = array_slice($a, 0 , date('N') -… phpanswered Papa Charlie 8,721
- 
		1 votes1 answer312 viewsA: Mysql How to return only part of the result of the FULL-TEXT queryFrom what I found, you can make a combination of LOCATE and SUBSTRING to cut the text based on the position of the word. LOCATE The first syntax Returns the position of the first Occurrence of… 
- 
		2 votes2 answers215 viewsQ: Apply the CSS of a child of element A to another element BIt is possible to somehow use CSS rules applied to #elemento > .filho in another element #dots? #elemento > .filho{...} In case I would need <div id="dots"></div> received the… 
- 
		1 votes1 answer54 viewsQ: Using variablesI had my eye on the use of variables in CSS, like below, simple stuff, so far so good. Then I saw that I could incorporate 'functions', but I only saw the use of libs as lesscss and Sass. You can… 
- 
		1 votes2 answers406 viewsA: Return with json array showing only first recordif($result->num_rows > 0){ $obj = $result->fetch_object(); $arr['result'] = true; $arr['dados']['endereco']= $obj->ENDERECO; }else{ $arr['result'] = false; $arr['msg'] = "USUARIO… 
- 
		1 votes1 answer85 viewsA: How to pick variable with $_GETYour rule must contain [QSA,L]. The flag QSA means you will accept a sequence for consultation. The flag L means that if the rule matches, it will not process the next string Change the order of… 
- 
		0 votes3 answers85 viewsA: preg_replace to change image srcYou can make a simple replace by replacing the http://www.domain.com.br by your url. $str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. <img… 
- 
		5 votes2 answers426 viewsA: $_GET[] does not workYou need to use isset to check if get has the index. if( isset( $_GET['load'] ) ) { if( strpos( $_GET['load'] , '/language/' ) !== false ) { $loadurl = file_get_contents("home.html");… phpanswered Papa Charlie 8,721
- 
		1 votes3 answers145 viewsA: How to have id security exposed in links - PHP + JavascriptMy problem is related to security since it may have a nasty user who changes the id of that button and access improper data or delete it[...] Assuming that you only allow the proper actions to be… 
- 
		4 votes1 answer1601 viewsA: PHP PDO error handlingIn case you’re wearing namespace declare the class with the backslash just below the namespace, use \PDOException, or in the code block itself catch (\PDOException $err). namespace XXX; use… 
- 
		3 votes2 answers109 viewsQ: Custom typingAccording to the DOC Type handling, the conversions allowed are: (int), (integer) - molde para inteiro (bool), (boolean) - converte para booleano (float), (double), (real) - converte para número de… 
- 
		4 votes0 answers24 viewsQ: Check connection statusI wanted to prevent the connection offline user made unnecessary requests not to have to wait for return timeout or any other mistake... Is there any javascript function able to check the status of… 
- 
		2 votes1 answer37 viewsA: Is it possible to count organic search visitors?HTTP_REFERER 'HTTP_REFERER' The address of the page (if any) through which the user’s agent accessed the current page. This policy is informed by the user’s agent. Not all browsers generate this… 
- 
		9 votes2 answers426 viewsQ: Is there a way to break in If?I was wondering if there’s some kind of break on IF. My doubt is based on the example below. When the function b() returns false all following comparisons are not performed. I thought the condition… 
- 
		6 votes5 answers426 viewsA: Explodes with name indexes (associative)In addition to the alternatives with explode, you can use preg_match. Simply inform the nominal indices in the rule itself. $string = 'Diego:25:RJ';… phpanswered Papa Charlie 8,721
- 
		1 votes3 answers316 viewsA: Separate values from a string and execute a function with the sameUsing preg_match_all to get the numbers only. You will have an array as below. Array ( [0] => Array ( [0] => 13 [1] => 123456789 [2] => 14 [3] => 123456780 ) [1] => Array ( [0]… phpanswered Papa Charlie 8,721
- 
		5 votes2 answers59 viewsA: Merge variables and include 0 to an 11 digit php fieldIf the store number and the environment number are ALWAYS preceded by zero, you can use str_pad to create the repetition of zeros. str_pad( 1 , 11 , '0' , STR_PAD_LEFT ) // 00000000001 str_pad( 10 ,… 
- 
		2 votes1 answer347 viewsQ: Authentication via social networksI am implementing authentication via Facebook and Twitter, and later other networks, but some doubts arose. What would be the logic for creating a new account when the user authenticates via social… 
- 
		0 votes0 answers67 viewsQ: Save database from another HDI had a main hard drive with my webserver - Apache, PHP, Mysql - but it gave problem and could not access anymore. I had to format a new hard drive and reinstall my environment. The problem is that… mysqlasked Papa Charlie 8,721
- 
		4 votes5 answers40467 viewsA: How to redirect php pagesMissing use the fetch_assoc to recover the value of profile. The command $mysqli-> query( ... ) returns an object and not Row. $result = $mysqli->query("SELECT `perfil` from login where… 
- 
		2 votes1 answer261 viewsA: PHP convert a sentence with and commercial (&) in arrayAs @Sergio said, PHP does this automatically if it is a URL. If this is any string, you can use the function parse_str. parse_str ( string $str [, array &$arr ] ) Converts str as if it had been… 
- 
		1 votes3 answers552 viewsA: Text registration with emoticonsUsing preg_replace you can map the emoticons and replace them with their corresponding image. Inserting the image directly or formatting an element using css. Note that the example will return… 
- 
		1 votes1 answer27 viewsA: Problems when instantiating the objectTo use chaining of methods, the method select need to return the instance itself. Just use return $this in the chained methods. public function select($sql, $array = array()) { ... return $this; }… 
- 
		2 votes1 answer400 viewsA: Place comma between wordsIn your case, $respostas will always be the last element - in case D - because there is a rewriting of the variable $respostas. The first loop contains To, the second she changes to B... so on until… phpanswered Papa Charlie 8,721
- 
		1 votes1 answer860 viewsA: problem with "inspect element"Actually it is not a problem, but it would be, if the user manipulated the value of id="110" and change any record that you are not allowed to change. Assuming the system only allows the user to… 
- 
		30 votes4 answers4172 viewsQ: Creating a CDN - content delivery networkWikipedia Networked computer system via the Internet, which cooperate transparently to provide content. CDN are usually deployed in multiple locations. Benefits include reducing bandwidth costs,… 
- 
		0 votes0 answers57 viewsQ: Email and password visibility after Ubmit (Facebook)I have a question about passwords. I decided to do an "experiment" to see the security of data sent by forms, and even using security protocol I noticed that it is literally possible READ AND SEE… 
- 
		3 votes0 answers1130 viewsQ: Rotate image while maintaining aspect ratioI need to rotate an image and maintain the ratio relative to the parent DIV without 'escaping'. I’m just using rotate(90deg) and the original image properties, as in the example. There are some… 
- 
		3 votes1 answer35 viewsQ: Grab a plugin selectorI’m trying to create a plugin but I can’t catch the selector, and it was even removed from version 1.9. If I use $(this).selector in the plugin, it returns a string #div #elementoA, #div #elementoB.… 
- 
		1 votes0 answers67 viewsQ: Single tooltip in 2 elements (one body and 2 arrows)I don’t know if the native code of Bootstrap allows this for the tooltip or for the can. I have 2 links and I need to do something that is created a tooltip or a can that can join both links with 2… 
- 
		9 votes3 answers156 viewsQ: Regular expression to reorder stringI have the result of a query with several joins, and in a row I have the concatenation of 2 groups. The line returns me a string as: 1,4|a1,b4. What I need is to regroup ID and Valor as follows:… 
- 
		0 votes1 answer50 viewsQ: Sum operations with sprintfIt is possible to do sum operations with sprintf? In the example below, how to decrease, or add 1 in $idade? $idade = 10; $str = '%d anos'; echo sprintf( $str , $idade );… phpasked Papa Charlie 8,721
- 
		2 votes3 answers6345 viewsA: In PHP, what is the best way to print a variable through a function?private function teste() { echo 'teste'; } The test method prints a value, and returns nothing, so, echo $this->teste() is the same thing as $this->teste(). $variavel = $this->teste(); echo… 
- 
		20 votes4 answers850 viewsQ: Return all equal items from different groups------------------- - TABLE - ------------------- ID | GRUPO | OBJETO ---|-------|------- 1 | 1 | 1 2 | 1 | 2 | | 3 | 2 | 1 4 | 2 | 2 | | 5 | 3 | 1 6 | 3 | 2 7 | 3 | 3 | | 5 | 4 | 1 6 | 4 | 3 | | 7…