Reading of line breaks wordpress

0

I have been trying for several days to find a solution, in php it is a bullshit and I have managed to solve it, but when it comes to coupling it to my impossible wordpress page.

The problem is the following one I want to create a list for each line obtained from the database, <li>EJEMPLO</li>     The issue is that I try to find when it is a "\n" o "<br />" and never finds it or because it omits characters. In the database the data is stored with a textarea that respects the line breaks.

Then I leave the code.

 for($i=0;$i<strlen(nl2br($row['starter']));$i++){
        if($row['starter'][$i]=="\n"){
            echo "<li>";
         }else{
            if(ctype_upper($resul[0][$i])){
                echo $row['starter'][$i];
            }else{
                echo $row['starter'][$i];
            }

        }

    }
    
asked by Lau550 24.01.2017 в 20:22
source

1 answer

0

I advise you to use the nl2br function when inserting into the database. That is, save the text with <br> .

But for now this should work.

$texto = str_replace("<br />","<br>",$row['starter']);

$texto = str_replace("\n","<br>",$texto);

$texto = explode("<br>",$texto);

echo '<ul>' ;

foreach($texto as $item){ echo '<li>'.$item.'</li>'; }

echo '</ul>';

    
answered by 29.01.2017 в 03:09