Dismember variable, taking part of the text

Asked

Viewed 119 times

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 dismember this variable to show the result, but I need to remove the comma, take only the part that is after the "-" of each color.

Ex:

Azul
Verde
Vermelho 
Preto
Branco

How could I do that?

1 answer

0


I managed to make it work in the following way in case 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.

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.