Forum Moderators: coopster
First of all let me tell you that i am very new to php. I am getting some hands on practice with trial and error while i am customizing some sections of some scripts.
These days, I am working on entering data through php file to mysql. Everything going fine so far. The only problem i am having is. Some fields i have to leave line breaks. I created scrolling text box on my template and enter there with line breaks for example:
Business Hours:
Monday - Friday
9.00 AM - 4.00 PM
Sunday
Closed
i enter excatly like this and since the field i specified in mysql is text it seems ok there too. However, when i want to display it on my html template it comes like this.
Monday - Friday9.00 AM - 4.00 PMSunday Closed
I cant get rid off from this problem and i would definetly appreciate if someone can let me know what is the solution.
Thanks in advance.
Should i used this function when i am submitting the data i mean should i use it on the form page that i submit the data or on the template page where i display the data.
Also, i would definetly appreciate if someone can write me a sample to use it. I was checking php.net web site about this function but it seems kinda confusing i tried some but didnt work
Thanks a lot
is this information editable?
if it is then when you load the form you need to strip out the <br /> from the string or it will get an extra set of breaks everytime they edit
example for insertion (only for \n transform other security measures omitted)
if you have a textarea called "bizhrs" and they enter data as you showed above and then hit submit you would have this data available in the $_POST array. You could then use nl2br before you pass it to your insert
$bizhrs = nl2br($_POST['bizhrs']);
you could then use it in your insert
if it is editable then after you do your select to get the data then you could use str_replace [php.net] before you populate the textarea again. Using the same varname to represent the column from the db
$bizhrs = str_replace('<br />,'',$row['bizhrs']);
make sense?