By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Text formating after print

tolkienarda
100+
P: 316
hi all
I am working on a content management service and i need some help keeping formating.
what i am doing is recreating my site in an admin side and all of the articles on the site will now be in <textarea> boxes so admins can edit them and save the changes it is working but any formating they use dosen't seem to work. if they want to have a return
in the middle of their article the only way it will work is if they enter a br tag in the article. is there any way to keep also double spaces are turned to one. does anyone know how to fix all of this.

you can see the page at
http://www.steppinupwebdesign.com/cms/index.php
and the admin page is
http://www.steppinupwebdesign.com/cms/admin.php

thanks
eric
Feb 13 '07 #1
Share this Question
Share on Google+
12 Replies


Motoma
Expert 2.5K+
P: 3,235
This thread contains a discussion about converting line breaks to <br> and back.
Feb 13 '07 #2

tolkienarda
100+
P: 316
Hi
I know it is probably somthing stupid i did but that didn't seem to work

on the three pages of where i am trying to use this i have put a copy of my php into html comments so that you can see them. i also posted what i feel is the important part below.

http://www.steppinupwebdesign.com/cms/admin.php - the admin side
http://www.steppinupwebdesign.com/cms/index.php - the display page

[PHP]
<?

if (isset($_POST['hometxt1title']))
$title = strip_tags($_POST['hometxt1title']);
if (isset($_POST['hometxt1txt']))
$text = ($_POST['hometxt1txt']);
if (isset($_POST['hometxt1author']))
$author = strip_tags($_POST['hometxt1author']);
if (isset($_POST['location']))
$location = strip_tags($_POST['location']);

$text=str_replace(array("<br>","<br/>","<br />"), array("\n","\n","\n"), $text);


mysql_query("UPDATE articles SET title = '$title', author= '$author', article = '$text' WHERE location = '$location'");
$result=mysql_query("SELECT id, title, author, article, location FROM articles");
$row=mysql_num_rows($result);
?>
[/PHP]
Feb 13 '07 #3

Motoma
Expert 2.5K+
P: 3,235
I'm not quite familiar with what you are trying to do, so perhaps you could explain what, exactly, the error/bug is as I look at your page.
Feb 13 '07 #4

tolkienarda
100+
P: 316
hi

ok my admin page isn't labeled very well the first text box is the article title, the second is the author and the text area is the article. when typing the article if i press the enter button
it gets saved as one line

press the enter buttonit gets saved as one line

like shown above.

sorry about the unclarity
eric
Feb 13 '07 #5

Motoma
Expert 2.5K+
P: 3,235
Okay, after you submit, you will need to replace the occurrences of "\n" with "<br />". I have some sample code in the link I posted earlier to do just this.
Hope this is what you are looking for.
Feb 13 '07 #6

tolkienarda
100+
P: 316
Okay, after you submit, you will need to replace the occurrences of "\n" with "<br />". I have some sample code in the link I posted earlier to do just this.
Hope this is what you are looking for.
so i need to put it on the actual admin page before it submits or do i put it on the update page
and if on the admin page where

eric
Feb 13 '07 #7

Motoma
Expert 2.5K+
P: 3,235
so i need to put it on the actual admin page before it submits or do i put it on the update page
and if on the admin page where

eric
You need to put it where you want it like that.
Feb 13 '07 #8

tolkienarda
100+
P: 316
You need to put it where you want it like that.
Hi

for some reason this isn't working. i am not sure why but here is a sequence of everything that happens
[PHP]
if (isset($_POST['hometxt1txt']))
$text = ($_POST['hometxt1txt']);

$newtext=str_replace(array("<br>","<br/>","<br />"), array("\n","\n","\n"), $text);
$oldtext=str_replace(array("/n"), array("<br />"), $newtext);

echo '<br />', $newtext, '<br />', $oldtext, '<br />', $text;
[/PHP]

I am guessing that i am not using php v5 or above because the str_ireplace command made everything break

thanks
eric
Feb 13 '07 #9

Motoma
Expert 2.5K+
P: 3,235
What about the above code isn't working? I am not sitting in front of a server to test the code, so perhaps you could explain what is breaking?
Feb 13 '07 #10

tolkienarda
100+
P: 316
hi

i am not certain but my text isn't being printed with the break lines that i need

the output from that code when i enter:
asdf
asdf

is:
asdf asdf - this is the new text
asdf asdf - this should be the old text
asdf asdf - this is the original text


i do however belive i have found the problem
the information i am getting from my form dosen't have [returns] as <br> but is submitting the data on one line

thanks
eric
Feb 13 '07 #11

ronverdonk
Expert 2.5K+
P: 4,258
What is this line doing?
Expand|Select|Wrap|Line Numbers
  1. $oldtext=str_replace(array("/n"), array("<br />"), $newtext);
.
You have your slash n the wrong way around and you don't need an array when you only have 1 item to replace. The statement should be
Expand|Select|Wrap|Line Numbers
  1. $oldtext=str_replace("\n", "<br />", $newtext);
Ronald :cool:
Feb 13 '07 #12

tolkienarda
100+
P: 316
thanks i havent done anything with strings in php till now

eric
Feb 13 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.