1
How to concatenate letters/words if it contains "&" and there is space between them?
Example:
A & E COMERCIO DE ALGUMA COISA LTDA
EMPRESA P & C CONSTRUCAO LTDA
CAMARAO & CIA FULANO DE TAL - ME
// OUTPUT
A&E COMERCIO DE ALGUMA COISA LTDA
EMPRESA P&C CONSTRUCAO LTDA
CAMARAO&CIA FULANO DE TAL - ME
Good @Luishenrique, dear as it would be if it were the following
CAMARAO &CIA FULANO-ME
orCAMARAO& CIA FULANO-ME
with spaces on only a few sides?– smigol
You can use
preg_replace("/ ?& ?/", "&", $example);
. The?
matches in 0 or 1 instance, while the+
1 or more. Another option is to replace the?
for*
, which means 0 or more occurrences.– Molx
@smigol updated the answer considering the case that one side is already concatenated.
– Luis Henrique
brigado @Luishenrique
– smigol