Questions tagged as 'php'

4
answers

rtrim () to remove "br" also removes the letter "r" if it is the last letter in the string

If a string ends with an HTML tag, for example <br> or <hr> , when making use of the PHP function # to clean the tag, in cases where the letter immediately before is an "r", it is removed together with the HTML tag: E...
asked by 03.07.2014 / 06:32
2
answers

Is there a way to do a foreach with two variables at the same time?

I tried to separate by comma, but it did not work: foreach($dados as $d, $telefones as $t){} I know there are other ways to make this foreach work, but I wanted to get this curious. Is it possible to use two variables in a foreach...
asked by 19.01.2016 / 13:03
5
answers

How to get the current date and time without using the computer clock?

I'm having trouble with date , it takes my computer clock time and I wanted it to really get the right time. The result of the following code is that date will fetch from your host server. date_default_timezone_set('America/Sao...
asked by 13.03.2014 / 20:28
5
answers

What's the difference between starting an empty room and starting right with the value?

I see things like: $arr = []; $var = ''; $var; $var = null; What's the difference between starting the variable like this: $var = ''; $var = 'teste'; And start like this: $var= 'teste';     
asked by 20.10.2017 / 17:10
3
answers

How to identify which city the user is? [duplicate]

In some sites of purchases / services is made an identification or suggestion of the city that the user is to be able to show only the specific products / services of the city of the user. Detail, this will be used only for non-registered u...
asked by 29.12.2015 / 18:55
3
answers

Comparison between a numeric and an alphanumeric string

The following operation returns true: var_dump("1" == "1e0"); //1 == 1 -> true But if I add an "e" at the end of the second string, it returns false: var_dump("1" == "1e0e"); //1 == 1 -> false??? If you do the following, return 2...
asked by 26.08.2014 / 19:58
2
answers

Doubts with relationships in Eloquent

I am making a belongsToMany to retrieve several Users that are related to a Item . It returns me in the array all Users correctly, however I need to do hasOne of each User (I created in the model Us...
asked by 20.05.2015 / 04:42
1
answer

RFC6530 - Check if variable contains a well-formatted e-mail address in PHP

Recently adopted by Gmail as published in Official Gmail Blog , and as defined in RFC 6530 : Assuming a valida_email() function that would return Boolean: echo valida_email("té[email protected]"); // devolve TRUE echo valida_email(...
asked by 08.11.2014 / 01:48
3
answers

What is the difference between function and assignment for array?

I have recently made codes in my projects where I need to add items to an array, so I do not know if I should use native language functions like this: array_push($meu_array, 50); or simply assign the value, for example: $meu_array[] = 50;...
asked by 05.01.2018 / 17:30
2
answers

Is it wrong for me to use a static method to retune a collection of objects?

First of all, I know that I should not go out doing classes with several static methods but in this case I bring here, I do not understand why it can be considered bad practice. Let's say I have an MVC structure, in my model, I have all of th...
asked by 15.08.2017 / 02:13