Break apart, taking part of the text

0

I have a multiple select that saves the following format in the database:

1-Azul,2-Verde,3-Vermelho,4-Preto,5-Branco

Now I need to break this variable so I can show the result, but I need to remove the comma, just get the part after the "-" of each color.

Ex:

Azul
Verde
Vermelho 
Preto
Branco

How could I do this?

    
asked by anonymous 08.12.2017 / 11:47

1 answer

0

I was able to do this as soon as someone else has the same problem:

<?php

$string = $ativos_u; //aqui eu pego string vinda do BD
$array = explode(',', $string); //aqui explodo as virgulas que separam

foreach($array as $k=>$v){
list($cod, $ativo) = explode("-", $array[$k]);
echo '<a href="principios-ativos.php#ativo'.$cod.'">'.$ativo.'</a>';
} //Depois faço um foreach com uma lista para separar o codigo do nome e exibo cada um separadamente usando uma lista.

?>
    
13.12.2017 / 11:25