Text ordering

0

In a form I have a textarea at the time of entering data the income of the following form.

But when I call it from the database it pulls me like a line

Is there any way to get it sorted out as you entered it at the beginning? I'm using codeigniter. I hope you have explained well greetings.

    
asked by MoteCL 28.09.2017 в 18:29
source

2 answers

1

In order to present the data the way you want, you could use the explode and then go through the data in foreach to add a line break. Something like this:

$s = "-Requerimiento 1 -Requerimiento 2 -Requerimiento 3";

$r = explode("-",$s);

foreach($r as $key => $value){
    if($value != null){
      echo $value."<br/>";  
    }
}

This will give you back:

Requerimiento 1 
Requerimiento 2 
Requerimiento 3
    
answered by 28.09.2017 / 18:43
source
0

The problem is that in a textarea the line breaks are established with the command "\ n". If you paint this string in a browser you will not see this line break because in html the line break is the <br> tag.

If in the textarea you write -requerimiento1 <br> -requerimiento2 <br> ... you will see as if later that the line break is reflected.

You must convert \ n in <br> . You can do this before uploading the form in javascript. Before saving it in db in PHP or reading it before using the data.

To change the codes in javascript:

... HTML ...
<textarea id="userText"></textarea>

.... JS ....
//con jQuery    
var value = $('#userText').val();

//sin jQuery
var value = document.getElementById('userText').value;

In PHP there are several alternatives. Replace characters with str_replace for example.

    
answered by 28.09.2017 в 18:44