473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Text formating after print

tolkienarda
316 100+
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
12 1841
Motoma
3,237 Expert 2GB
This thread contains a discussion about converting line breaks to <br> and back.
Feb 13 '07 #2
tolkienarda
316 100+
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
3,237 Expert 2GB
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
316 100+
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
3,237 Expert 2GB
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
316 100+
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
3,237 Expert 2GB
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
316 100+
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
3,237 Expert 2GB
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
316 100+
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
4,258 Expert 4TB
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
316 100+
thanks i havent done anything with strings in php till now

eric
Feb 13 '07 #13

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

Similar topics

6
by: Polar | last post by:
I have a database that stories entries of short stories for a writers website. I can easily input the data into MYSQL but my trouble lies in retrieving the data. the story in just cut and...
24
by: =?Utf-8?B?RHVja3dvbg==?= | last post by:
Hello, My code is suppose to write to an existing file. But after my C# code appends the file, the previous text loses all the endline characters, becoming one long line. How can I retain the...
1
by: Shawn Northrop | last post by:
I just read an article on kirupa.com about incorporating mySQL and PHP with flash. I am dynamically loading conent into a flash movie and am not sure how to format. In my php code i have: $y = "";...
7
by: sphinney | last post by:
I have a datasheet style form with textbox (MyTextBox) that has the Text Format property set to "Rich Text". It is bound to a memo field in a table. How do I change the text or highlight color of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.