1
I have a problem with an appointment SQL
on the basis of a array
.
I am concatenating the values received from a text-area, by sql
with a IN
, follows sql example:
select * from jupiter where imei in ('352997100159046 ','351758105120669 ','357770077861257 ','358492061345614')
And based on this query return the data to a table. It happens if they repair has a space ' '
after numbering, and for some reason does not return the data in PHP (In the database ide returns normally).
I tried in several ways to remove this space, follows examples:
$final = str_replace(' ', '', $manipulado2);
$str = trim(preg_replace('/\s\s+/', ' ', $final));
I also created an array with characters that I do not want and removed them but also without success:
$caracteres = array(" ","a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",".",";"," ", "^", "~","-","!","@","#","$","%","¨","&","*","(",")","=","+","\r\n");
But in no way I can remove these spaces from my query.
These data are wrong in a vector, follows explanatory image:
As you can see at last it does not contain the space and it returns the correct search.
It follows how the concatetion is being made (in a very primitive way but it is how I managed to do):
I receive via post the data of a textarea that is separated by enters, and replace the line break by ','
.
$resultado = str_replace("\n","','", $_POST['imeis']);
Here I call the function that this row above is and separate into the comma and put that into an array.
$array_informado = explode(',', trata_imei());
Then I throw it to one foreach
to show off in my table
:
print_r($array_informado);
foreach ($array_informado as $rows){
This print_r, is what printa in the image above, it already brings the information with the spaces!!
Does anyone know why these spaces are not being erased from my string?
Thank you!
The problem could be in the concatenation. You should show in the question how this is being done (put an example of the textarea with the data -- if you have line breaks etc. -- and the code that concatenates).
– Sam
I’ll put it right away!
– Vinicius Candido
@Sam Edited!!!
– Vinicius Candido
a demon won’t fix?
– wribeiro
I tried with Trim, it doesn’t solve either :\
– Vinicius Candido
I have the impression that it identifies as if it were a different character, or so understand that the character is the full number + the space, and not just the space...
– Vinicius Candido
In the
preg_replace
, a regex/\s\s+/
requires at least 2 spaces (one\s
corresponds to one space, the other\s+
is "one or more spaces", that is, it has to have at least 2, so it does not replace anything). Maybe only dopreg_replace('/\s+$/', '', $final)
already solved - although thetrim
should remove anyway. I don’t know, thetrim
only removes a few characters (see documentation) but Unicode defines other "space" characters, maybe it is one of those: http://www.fileformat.info/info/unicode/category/Zs/list.htm– hkotsubo
I found something similar link
– wribeiro
I believe this is the way... I tried it this way
$str = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $final);
but without success. the return was'352997100159046 ','357770077861257 ','351758105120669'
– Vinicius Candido
I’ll give an Edit in the post, please see
– Vinicius Candido