0
I have a column in the database that saves a free text, and together is saved some data within [ ]
is to find only what is inside [ ]
in this string to convert it to an array.
Example:
$texto = "Hoje fomos até São Paulo visitar o paciente, [236,AD-BF] e não foi possível chegar a um diagnóstico";
I would like to extract only the [236,AD-BF]
and turn it into array.
There’s some way to do it?
$array = explode(',',$texto);
The funny thing I see here is people negativate without at least leaving a justification, it would be good to know the reason to be able to better where I went wrong, I am not against negativar I am even favorable because it helps us to evolve.
– WMomesso
you just want a solution for this specific case or want a reusable thing for other phrases?
– Thiago Drulla
But the text to be extracted always comes within
[]
? There’s only ever one block[]
?– Isac
It would be something that is reusable for other phrases that contain the same string pattern
– WMomesso
The text to be extracted always comes within
[ ]
and each string will have only one occurrence– WMomesso
Of a researcher in the function
preg_split
, he is one of the possible solutions– Thiago Drulla