Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Commas


Hi everyone, I would like to be able to insert commas into a number every three spots. Like if I had 1728, a comma would be insert between the 1 and 7. The number is random so I need to know if there is a works-for-all-numbers.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Commas In CSV
I have built this form in php and when I click on it, I am storing all the fields in .csv file. There is one field known as address which can contatin commas How can I make it so that when I open it in excel address remains below address as in the commas submitted for address in the form becomes part of the address.

Commas In #'s
ok i want to put commas in #'s like 3,000,000,000 ok. ok say the number is $player[gold] and say that it is 3000000 how do i add commas?

Add Commas Between Names
i've got a script that pulls first name, last name, and suffix from a DB query and echos them only if they are not null. the names are cross-referenced by id number from two other tables. it displays the name pieces that are not null for each "job", and the jobs and names are determined by another id number for an individual issue page. an example of the output is here: Code:

Getting Rid Of Inverted Commas
If someone types 'Tom's Photos' into a input field i need a piece of code that removes the " ' " when the information is processed.

Example
Tom's PhotosScript Processes InformationScript Finds the " ' " in Tom'sScript Removes " ' " in Tom'sResult Is Toms.

Inserting Proper Commas Into An Integer
I've looked and looked, and I can't find anything about this, and it's driving me nuts! All I want to do is insert a comma into a long number (when applicable) to make the display look nicer. This script is counting pageviews on my site, so it'll be a large ugly number in a few days.

For example, instead of displaying:

1876235

I would want it to display

1,876,235

The integer could be any size (potentially), but I don't see any need to worry about numbers beyond 8 digits. Any suggestions?

Regular Expression, Exclude Commas
Greetings all. I'm a newbie, desperate to learn, and I've searched here and Google for such things as "PHP regular expression comma" and variations on that theme, but I haven't been able to figure out what I'm doing wrong, though I've visted several sites and tutorials dealing with regular expressions.

I've got a form on my bosses' Web site where a customer can enter a price range and get a list of our "stuff" that falls within that price range. I'd like to set something up so that if they enter letters or commas or anything other than numerals in the price range form fields, they'll be gently encouraged to go back and do it right. :)

This is what I've got for the time being:

if (!eregi('^[0-9]', $pricemin) ¦¦!eregi('^[0-9]', $pricemax)) {
echo '<P>You have not entered a valid price range. '
echo 'Be sure to enter only numbers, and no letters or punctuation marks, when searching for a price range. '
echo 'Click the Back button on your browser to search again.'
exit;
}

This works, insofar as if someone types "blah" in the pricemin or the pricemax form field, they'll get the message. But if some well meaning person types "50,000" or "$50,000" instead of "50000" in there, they currently get a MySQL error. I've got a note telling people not to use letters or punctuation, but you know how people are.

All the tutorials I've seen talk about including or excluding different characters based on different criteria, but everything I've tried to put a comma in there has failed and/or messed up the query somehow. What am I missing?

Stripping Commas From Real Numbers
I have an HTML form in a PHP script which queries the user for a dollar amount of sales.
If a user enters "1,000,000" rather than "1000000" for 1 million, PHP (or MySQL?) treats the commas as a decimal and "1" is entered in the database.

A simple work-around is to simply advise the user "Please enter numbers only, no commas or $'s" but this seems awkward. Is there a built in function or another easy way to have commas and currency signs stripped out of form-entered data?

Printing Numbers With Commas Every Third Digit
how do you print numbers with commas every third digit?

like this: 1234567 to this: 1,234,567

Stop The Commas!!! ( Or Knowing When You're At The End Of An Array )
I am looking for a good way to know when I am at the end of a
comma-separated list of array values.

My code is simple (as well as I'm sure is the solution I'm looking for;
and YES I've search the php manual!! Arrggghh! )

Anyway the code goes like this:

...

<td><select name="pref_cities[]" multiple size="6">

<option>Nagpur</option>

<option>Mumbai</option>

<option>Bangalore</option>

<option>Chennai</option>

<option>Kolkatta</option>

</select></td>

...

<?php

$cities = $_POST['pref_cities'];

foreach ($cities as $city) {
echo $city . ", ";
}
?>

I want to know when I'm at the last element in $cities[] so that I can
output a period (.) instead of a comma (,).

Adding Commas To Large Numbers
I have a search that when you search it shows how many results you are being shown and usually the number is between 100,000 and a 1,000,000 how can i add commas to a number for example: 989725?

Strip Out Commas And Characters In A Text Box
I have a form that the user can enter a number in the text field and a calculation is then preformed with PHP when the form is submitted.

$amount = $_POST['amount'];

<input type="text" name="amount" size="20" value="">

Any way to strip out commas and any characters that may be entered. I would like an entry like $5000, 5000, 5,000 and $5,000 all to be passed on to the PHP script as 5000. The way it is now the php math script treats 5,000 as a 5 and $5000 as a 0.

Comma Delimited Csv Has Commas Inside Fields
I need to import a CSV file into a database daily. That operation in itself is simple enough but the trouble is that some fields are quoted because they have commas inside them. How do I handle this with my import script?

It would be much better if the CSV was created with all fields quoted or used a different delimited but sadly that is not an option.

Change Alternate Commas To Semi Colons...
With a string of authors such as:

I would like to write a function to change every other comma into a
semi colon (thereby defining where one name ends and the next begins).

I could do it by writing a complex (and slow) procedure - but is there
a quick way of doing it using regular expressions, for example?


My Data Contains Commas And Pipes "¦"
I have some raw data that I was planning to insert into a flat file and then upload/insert into my mySQL DB.

However the data contains commas and pipes "¦". I usually use the ¦ as my delimiter.

Before I upload the data I wanted to remove dupes which happen to be text/blob fields. I usually do this in access.

I thought I could get around this by using quotes as a text qualifier. It didn't seem to work. My other method I usually try is to use some combination of characters like <¦¦> as a delimeter.

However Access only allows one character as a delimeter and phpmyadmin only allows two characters as the delimeter.


Copyright © 2005-08 www.BigResource.com, All rights reserved