Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I format data 3

Status
Not open for further replies.

kzn

MIS
Jan 28, 2005
209
GB
I am busy making a test CMS or should I call it a forum system. At the moment I can enter data in my form, this is then inserted into the database. I can then redisplay the data and edit it. I am using the nl2br() function to return my data.

I have two problems:
1. I can not make bullet points. When I display the data it is all aligned to the left.
2. I need to be able to insert hyperlinks

I can not expect users to put <a href="">link</a> or put &nbsp; in front of say 1. to move it over... and from what I have read users should not be able to insert code.

I am really stuck and I wonder if there is a solution for something like this. I would appreciate any help if you can point me in the right direction.

Thanks in advance. :)
 
I'm not sure what you are asking. You can output any html you need at the time you output your text. So assuming you need to link something you would yourself output the <a href> html for it where you need it.

Code:
echo "<a href=$row['fieldfromadatabase']>$row['otherfield']</a>";

Or if you need to output a list you cna use the <ul><li> html and get the bullets.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for the response.

My problem is the following:
A user goes onto my page and inserts a story in form and then saves the data. Some of the text they have inserted is indented ie
1. This is the first.
2. This is the second.

My problem is that when the page displaying the data is viewed, 1 and 2 above are left aligned(there is no indent).
How do I make it keep the indent.

The second problem is:
How does a user insert a link into their story when they are writing into the form field. They will not want to type <a href=""> is there a easier way of fixing this.

Hope this makes sense
Thanks for any help.
 
when you output the story wrap it in <pre> ... </pre> tags.

there is no way to create an html link without using html.

if you are looking to make the inputter's life easier then consider a wysiwyg input control such as fckedit or tinymce

 
Thanks Jpadie

I have done as you suggested and wrapped the output in <pre></pre> tags but I am still getting the same problem.

This is how the whole process works:
The form is submitted
The data is passed through the following function to clean it up before inserting it into the database.
function escape_data($data) {

// address magic quotes
if(ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}

// check for mysql_real _escape_string
if(function_exists('mysql_real_escape_string')) {
global $dbc;
$data = mysql_real_escape_string(trim($data), $dbc);
} else {
$data = mysql_escape_string(trim($data));
}

return $data;
}
Another page displays the inserted data using the following code, I have tried inserting the <pre> tags and no joy.
$story = "<pre>".nl2br($row[0])."</pre>";

Thanks again
 
The last bit of jpadie's post suggests you need WYSIWYG control such as TinyMCE or FKEdit. I suggest TinyMCE.

You can't have the user input plain text and somehow magically transform it to HTML on output. It requires some kind of markup.

Using TinyMCE will give them a MS Word type interface where the HTML is generated for them behind the scenes. You then store the HTML in your database so when it's output, it's output as HTML.

I would also say that there are other options to WYSIWYG such as MarkDown or Textile. There is a neat, fairly new, editor floating around for doing this but I can't for the life of me remember what it's called at the moment.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
the trim functions may be deleting some of the white space (eg tabs). it may also be that the tabs are not getting into the server properly.

you could try running the input through a conversion routing first. search for \t and replace with, say, four, non-breaking spaces.
 
Thanks for the replies.
I did think of removing the trim and still it does not matter. The strange thing is when I have a look at the data using mysql front. I can see the data is indented. So it must be with my way of displaying it.
 
i am surprised, then, that <pre> tags do not work.
 
I suppose the next question would be where are you putting these <pre> tags. Could you show us the part of the generated html with the indented story inside the pre tags?

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Hi

Here is the code that generates the html code
$story = "<pre>".nl2br($row[0])."</pre>";

The output is as follows:
<!-- Content goes here //-->
<div>This is a test.<br />
1. First test<br />
2. Second test<br />
<br />

The end</div>
<!-- Content ends here //-->
 
I can't see any pre tags in that output. Plus, if you will wrap a div inside a pre element, there's a chance that pre will no longer work. You can combat that using the CSS equivalen to pre (white-space: pre;) on the div itself.

However, I think the best solution for you is still (as suggested by two members already) to use a WYSIWYG editor.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Thanks very much to all of you. I put the pre tags in my template and it has worked, it did not work with $story = "<pre>".nl2br($row[0])."</pre>"; for some reason. I will look at the editors. Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top