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
Two questions, 1 how to add 0s to a number and 2 how can I get newlines from textarea
Old 03-12-2008, 11:45 PM Two questions, 1 how to add 0s to a number and 2 how can I get newlines from textarea
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
The first one, I have this code:
PHP Code:
<?php $rnum rand(0,9999);
echo 
$rnum;?>
Quite simple for now, and I just want to add 0s if it's less than four digits to make it four digits long, so 0000-9999. I can't seem to find anything on this.

The second one is, how do I use a textarea and PHP and I guess maybe mysql too to save newspaces (which then I can convert to <p> and </p>, such as the post boxes on forums) I've not found anything on that either, but would like to be able to use it.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
 
Register now for full access!
Old 03-13-2008, 02:56 AM Re: Two questions, 1 how to add 0s to a number and 2 how can I get newlines from text
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
1. strpad()
2. store \r\n in the database, convert them to <p> or whatever before placing into html
__________________

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 03-13-2008, 03:30 AM Re: Two questions, 1 how to add 0s to a number and 2 how can I get newlines from text
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Thank you for number one, I knew I had seen a function to use before, how do I store \r\n in the database though?
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 03-14-2008, 01:43 AM Re: Two questions, 1 how to add 0s to a number and 2 how can I get newlines from text
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
If you receive your data from the client's browser textarea (because you cannot receive multiline input from input type="text") you can simply addslashes() to escape quote marks and store the whole text into your DB, all newlines will be preserved. Then after selecting your data from DB you simply do print(nl2br($text)). If you need to wrap your paragraphs into <p></p> you will have to do a little more work: first split() your text into array, add <p> to the beginning and </p> to the end of each array item and join() it back. Hope you already know how to iterate through arrays.
__________________

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 03-14-2008, 04:04 AM Re: Two questions, 1 how to add 0s to a number and 2 how can I get newlines from text
RadGH's Avatar
Skilled Talker

Posts: 76
Name: Radley
Trades: 0
Quote:
Originally Posted by Arenlor View Post
Thank you for number one, I knew I had seen a function to use before, how do I store \r\n in the database though?

Are you asking how to add them to the string of their input, or actually how to add their input to the database?

mtishetsky explained how to turn characters input <p> already.
RadGH is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Two questions, 1 how to add 0s to a number and 2 how can I get newlines from textarea
 

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.24032 seconds with 12 queries