Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-19-2008, 05:28 PM Formatting text
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Hiya

looked this up but can't seem to find the answer

How do i get my php page to read carriage returns and <b>..</b> tags but without allowing all the html code

at the moment if i entered

Y
E
S

it gets stored in the database as

YES

Thanks for any help

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-19-2008, 10:17 PM Re: Formatting text
vangogh's Avatar
Post Impressionist

Latest Blog Post:
Why Responsive Design?
Posts: 10,815
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Hi Sharon. I'm not sure I'm entirely following what you're trying to do. Is the idea that you're entering something through a form and then storing that in a database?

I'm also confused by you wanting to read <b> and </b>, but not allowing html.

Do you mind sharing a little more detail? I'll be happy to try and help.

I'm thinking there are going to be several options depending on what you're ultimately trying to do. For example when you enter:

Y
E
S

you could enter each character into the database with some delimiter in between each character so it would get stored in the database like

Y,E,S

using a comma as the delimiter. Then when you read it out of the database later you need to parse the string back into the individual parts.

You might also want to first put the values in an array and then store them using serialize() and use unserialize() when you want to read and use the values later.

Here's an article describing how.

I'm not sure if either of those is along the lines of what you're looking for and neither address the html portion of your question, but I hope it helps some.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 02-19-2008, 10:44 PM Re: Formatting text
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Hiya

When a user submits a post in the forum i am building... it all gets put on one line...

example

a user enters..
..................
Hello there
how are you?
..................

in my database that currently gets stored as

..................
Hello therehow are you?
..................

but i want to know how to pick up on the carriage returns and replace with <br> so it gets stored in my database as

..................
Hello there<br>how are you?
..................


Thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-19-2008, 11:04 PM Re: Formatting text
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
ohhhh i got it

it replaces

carage returns with

\r\n

i can use string replace and change that to <br>

Thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-19-2008, 11:13 PM Re: Formatting text
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
hmmm

in my form
if i enter

test
test

then echo it in my processing form

it shows as

test\r\ntest

with the "\r\n" being the page return

but if i use the command

$text = str_replace("\r\n", "<br>", $message);

it don't see the \r\n

and echos it as "texttext"

hmmmmmmmm
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-20-2008, 12:00 AM Re: Formatting text
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
hehe i know why

i was using my command after

$message = mysql_real_escape_string($message);

so it was stripping the hidden slashes hehe

now i am using it before that command it works fine

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-20-2008, 02:07 AM Re: Formatting text
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You should convert \r\n to <br /> only when putting the data with line breaks into html. You should store \r\n in your DB and put them unchanged into textarea to edit.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-20-2008, 05:16 AM Re: Formatting text
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
You should convert \r\n to <br /> only when putting the data with line breaks into html. You should store \r\n in your DB and put them unchanged into textarea to edit.

why not store the <br> ?
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-20-2008, 06:00 AM Re: Formatting text
RadGH's Avatar
Skilled Talker

Posts: 76
Name: Radley
Trades: 0
I don't know about storing the <br /> compared to the \r\n in your DB, but for your previous question(s?) you should check out these functions:

Allowing only specified HTML tags:
strip_tags

Converting characters to html entities (make > be &gt
htmlspecialchars
html_entity_decode

PS: <br /> is the correct way of using a <br>, although almost every browser will use it the same you probably won't pass XHTML validation. Not a big deal, just about any browser will treat it the same under standard circumstances, but its bad practice.
RadGH is offline
Reply With Quote
View Public Profile
 
Old 02-20-2008, 06:51 AM Re: Formatting text
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Because from the textarea after edits you will obtain mix of <br>'s and \r\n's and you will soon get all info screwed. You should have one generic way to convert between them to avoid the mess.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-20-2008, 06:54 AM Re: Formatting text
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Sharon, let the string in the db with \r\n it's the natural form for it.
Then , when you "echo" it, add a call to nl2br() in between:
http://www.php.net/manual/en/function.nl2br.php
PHP Code:
echo nl2br($string); 
and the \r\n (and \r and \n from Linux and Mac clients too) will be converted to a <br/> tag.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-20-2008 at 06:55 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-20-2008, 11:46 AM Re: Formatting text
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
ohhhh
i never knew the proper way was <br />
wow, even in the beginners html manual i started with about a year a go said it was <br> lol
Now i will have to go through all my pages and change <br> to <br />

don't you just love notepads find/replace function hehe

thanks

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-20-2008, 01:21 PM Re: Formatting text
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
the "/" at the end is the Xhtml empty node syntax.
In XML, like Xhtml, every nodes must be closed.
This is true for the br too, and the short syntax to have a empty node is
Code:
<nodeName />
or the complete:
Code:
<nodeName></nodeName>
This goes for any Xhtml element, like a hr, or even a td.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Formatting text
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39717 seconds with 12 queries