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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





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?




View Complete Forum Thread with Replies

Related Forum Messages:
Want Commas In Your Numbers?
Just made 2 functions for putting commas into your numbers. Also, these two functions with a little bit of syntax changes will work on TI-83 calculators, making it easier to awnser a question without looking like your using your calculator :). Code:

View Replies !
Adding Numbers With Commas?
<?
$var1 = &#3910;,000'
$var2 = &#393;.59'

$sum = $var1 + $var2;

echo $sum;
?>


I'm getting "13.59"

I'm obviously missing something pertinent to adding numbers with commas.

Any help?

View Replies !
Add Commas To Numbers 1034 > 1,034
I have a string: "1034" How can I dynamically add the relevant commas so it would show up "1,034", and if it changes to "7854355" make it show "7,854,355"?

View Replies !
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

View Replies !
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?

View Replies !
A Real Challenge For Real PHP Programmers
<?php
/*
A challenge to every PHP programmer.The one who's gonna solve this
problem would be deemed as

PSP(PHP Supreme Programmer).The problem is this : You have to write a
script that displays a list of

categories and subcategorieslike this one:

<select name="category">
<option value="1">Main</option>
<option value="2">Main > Computers</option>
<option value="4">Main > Computers > Hardware </option>
<option value="8">Main > Computers > Hardware > PC</option>
<option value="7">Main > Computers > Hardware > Mac</option>
<option value="9">Main > Computers > Hardware > Atari</option>
<option value="11">Main > Computers > Hardware > PC > History of
Pc</option>
<option value="">etc...</option>
</select>

The categories and subcategories details are stored in these two
tables in a MySQL database.
-categories : the categories names and ids.
-cat_relations : the relations between categories.It shows which
subcategory belongs to which category.
The belongings between categories can go very deep and the number of
categories is unlimited. This script will create the two tables and
fill them with sample data. All you need to do is to change the four
variables below. You can send the script back to this email :
yasbergy@yahoo.com.
*/

//Here starts the script. Please change the values of these variables
to fit your settings
$user = "prospective_PSP";
$database = "db";
$server = "localhost" ;
$pwd = "" ;
//Connection to the database that you created
mysql_connect($server,$user,$pwd) ;
mysql_select_db($database);
//Creation of the two tables : categories and cat_relations
$categories = " CREATE TABLE `categories` (`id` INT not null
AUTO_INCREMENT, `name` VARCHAR(100) not null , PRIMARY KEY (`id`),
INDEX (`id`), UNIQUE (`id`)) comment = 'The categories details' ";
mysql_query($categories) ;
$cat_relations = "CREATE TABLE `cat_relations` (`id` INT not null
AUTO_INCREMENT, `daughter_id` INT not null, `mother_id` INT not null ,
PRIMARY KEY (`id`), INDEX (`id`), UNIQUE (`id`)) comment = 'Which
category is the daughter of which category'";
mysql_query($cat_relations) ;

//Filling the two tables with sample data
$cats = array('Main','Computers','Countries','Hardware','S oftware','Programming
languages','Mac','PC','Atari','Winamp','History of the
PC','IBM','Components','High
level','USA','NYC','LA','Manhattan','India','Winzi p');
for ($i=0;$i<count($cats);$i++){
$sql = mysql_query("insert into categories (name)
values('".$cats[$i]."')");
}
mysql_query("insert into cat_relations (daughter_id,mother_id) values
(2,1),(3,1),(4,2),(5,2),(6,2),(7,4),(8,4),(9,4),(1 1,8),(12,8),(13,8),(10,5),(20,5),(14,6),(15,3),(16

,15),(17,15),(18,16),(19,3)");
//Now you can have a look on them through phpMyAdmin
?>

View Replies !
Display Numbers 1-20 Randomly Without Repeating Any Of The Numbers - Fatal Error: Maximum Execution Time Of 30 Seconds Exceeded
I make a code to display numbers 1-20 randomly without repeating any of the numbers. The result is fine but I keep on getting Fatal error: Maximum execution time of 30 seconds exceeded. Personally I don't think PHP will have much trouble going through the loop. Here's the code:

View Replies !
Change Straight Numbers Into Phone Numbers?
How can I change these two numbers into phone numbers?

5551231234
9009876789

echo INTO:

(555) 123-1234
(900) 987-6789

View Replies !
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 Replies !
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.

View Replies !
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?

View Replies !
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:

View Replies !
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.

View Replies !
Extracting Between Commas
I'm working with a database that would take me days to change to the correct format so I'm in need of a workaround. Is it possible to extract text that is in between two commas?

I have a long string with multiple commas seperating the values, but it's only the 2nd line that I need for passing on in my code. The best way to explain is example:

What's in the database:

text123, WHAT I WANT, more stuff, another line of junk, both letters and #'s

Can I create a function that turns a variable into "WHAT I WANT"?

I know this is weird, but this database has 20,000+ entries and the "part number" I need is within one of the fields...and it's the only way to identify what I need.

View Replies !
Delete All Commas
How do I delete all commas from a string? I tried the explode/implode way, but it slows down the script a lot. I looked for an alternate function -- something like delete() like they have in pascal/delphi, but no luck.

I have a number: 1,813,445 and I just want to remove the commas. Then use that number in an arithmetic equation, and then put the commas back in by using...

number_format($str, 3)

but when I use the above function, I get a number like 1,813,445.000. Is there a way I can receive the number without receiving the .000 and without using substr?

View Replies !
Encode Commas
I have data that i want to add to a field that has a comma in it. If I do a straight input, it will mess up the column count. How do i handle this.

View Replies !
Commas In Queries
I'm outputting data from my database. I'm using $_REQUEST to get a value to query my database e.g news.php?headline=new headline.

I'm then searching for 'new headline' in my database and outputting the related information.

My problem is that it isn't working for any headlines with commas in them eg.
'News Headline' todays news. It can't seem to find anything in the database if it has a comma in it.

When I add to the database, I used addslashes(). I'm not striping the slashes...could this be why? But when I look in the database, there doesn't seem to be any slashes in there?

View Replies !
Commas In Links
I am creating a link and then it has text. I want a comma to display in the text but not sure how to do it. If I put the comma it will not show the rest of my text. Code:

View Replies !
CSV File And Commas
I have a database that has a field where commas are used:

PID PNAME PTYPE
011 hello small,medium,large

In PTYPE above, commas are within the field. I would like to export this table to a csv format but how do I tell it to NOT read the commas within a field as the deliminator.

View Replies !
Dots Versus Commas
What is the difference between using dots or commas. I got some help with a script I'm using and the person used dots where I originally used commas.

The script is working fine, but I'm trying to learn to write good code instead of just code that works. If there's something bad about using the dots, I'd like to know how to fix my script so it's right.

View Replies !
Change All Commas To A Space
The following works fine for replacing "normal" words in a MySQL table:

UPDATE tablename SET fieldname=(REPLACE (fieldname, 'oldword','newword'));

However, I have a situation where I need to change every comma that appears as text in a particular field to a space. How would I do that?

View Replies !
Script/Code For Commas
If i want all numbers to contain commas like 123,456,789 how would i do that right now they are 123456789 and i want it so they all contain them how would i do this? btw the numbers change automatically on there own.

View Replies !
Commas In Numerical Values
I want to know if there's a way to include commas in numerical values in a database. I have a lot of integer (INT) rows but I cannot include commas, so instead of 10,000 I can only enter 10000.

The reason I want this is because in the output, I want all numbers to have commas. Is there any way around this?

View Replies !
Seperate String By Commas
I have a string that I want to create into multiple hperlinks where it is seperate by commas.

Ex: $names = "john, dave";

Now I'm trying to make URLs from each name:

$splitdata = explode(',', $names);
echo "<br><a href="http://www.mydomain.com/search.php?name=$splitdata[0]">$splitdata[0]</a>, <a href="http://www.mydomain.com/search.php?name=$splitdata[1]">$splitdata[1]</a>";

Obviously this is the wrong way to go. Because there are instances where the variable has more than two names, and I'm not counting the instances in the above example.

View Replies !
Random Numbers Being Created But All The Numbers Have To Be Different
I want four random numbers being created but all the numbers have to be different. For example: no 1,2,2,4 or 4,3,1,1, etc... For example a right result would be 3,4,1,2.
So no double numbers. PHP Code:

View Replies !
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?

View Replies !
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?

View Replies !
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 (,).

View Replies !
Comparing Arrays - Separated By Commas
I have a MySQL database which has a load of musicians on it. Each musician has a field that stores their influences, which are separated by commas, e.g: The Beatles, The Beach Boys, Kiss etc etc.

Now, what I would like to do is start with the influences of one musician, and then compare it to all the others to find the closest matches - i.e find the musicians that have (say) more than three influences i common. This would then allow you to see which musicians had the most influences in common with the primary one, the one you started with.

Here's what I have in mind, it seems a little laborious - load the influences of the primary musician into an array using the explode command. Then step through each of the other musicians in a loop, each time putting their influences in to an array and checking to see how many matches there are between the two arrays. Whenever there is at least one match, the name of the musician and the number of matches would be put into a third array. This array would then be sorted at the end, so that the musicians with the most matches would be at the top, and the script could then display them.

This would probably work, but if looking at several hundred or several thousand musicians, it would surely be quite slow - is there a better way? I don't particularly want to use a separate, normalised table at this point - I know it would be the quickest way but it would involve a lot of restructuring for me. I know that PHP has several clever inbuilt routines that might do this job for me, so if anyone can suggest anything I'd appreciate it.

View Replies !
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.

View Replies !
Error When TextBox Has Inverted Commas
I Have a TextBox (Rich Text Box),and that textbox value goes to next page which is used to INSERT data into db, and whenever that textbox contains "" inverted comma's then on Mysql Db it show and cut off the remaining text, For Example

Hello World
I am Johny, I Love Blah Blah and my Favourite Movie is "XyZ" and i love soccer

Now On Db this Text looks like

I am Johny, I Love Blah Blah and my Favourite Movie is

Anyone Have Solution?

View Replies !
How Can I Restrict The Input Of The Text Box To Not Allow Commas?
I have a php form that collects information and inputs the information from multiple pages into a pdf file. The forms store the information in a CSV file. One of my questions asks for a particular location. If someone input the loaction such as "Miami, Florida" the comma throws off the formatting. How can I restrict the input of the text box to not allow commas? I tried a javascript validation script, but that caused an error.

View Replies !
Commas(in Float/decimal) And Sql Escaping
It is not possible to enter &#391;,000.52' into mysql (as float or double). So it has to be escape. (1000.52). How do you escape? I know about str_replace(). Interesting to know what other function will do it.

View Replies !
Ignoring Commas In Individual Fields
I'm trying to develop a bullet proof CSV function that can ignore commas that are found in individual field data when parsing through a regular CSV file. Here's some of the code I'm trying right now:

$file = fopen( $file_name, "r" );
$cnt = 0;
while( !feof( $file ))
{
$line = fgetcsv( $file, 4096 );
$count = count( $line );

if( is_array( $line ) && $count > 0 )
{
for( $i = 0; $i < $count ; $i++ )
{
echo "<br>$line[$i] ";
}}}

fclose( $file );

View Replies !
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.

View Replies !
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?


View Replies !
Formatting A String And Strip Out The Extra Commas
if i have a string like this:

id=14,15,16,17

and some of the ids can be missing
e.g. id = 14,,16,17

I would like to strip out the extra commas. Ive had a few goes trying different ways.

View Replies !
Easiest Way To Get Commas & Spaces Through A Hidden Post
I have a string that will hold data like "July 09, 2005 at 10:00 am"

and I need to post it as a hidden value from one form to the next. What's the easiest way to get the comma, colon and spaces to make it through?

View Replies !
Function Code To Highlight Concatenated Results In Inverted Commas
I have a function that I'm using to highlight search terms in the results page: Code:

View Replies !
Real Ip Behind A Proxy
is there any way to know the real ip, for people behind a proxy?

View Replies !
Getting The REAL Directory?
Is there any way to get the directory/path of the file running the script, not the directory you're inside (Via dir())? I'm allowing the user to navigate through directories, and that part works great - but whenever I attempt to used getcwd(), it returns the directory the user is in - not the directory of the php file - is there any way to get the directory of the .php file the user is using?

View Replies !
Real Estate MLS/IDX
I am trying to program an MLS/IDX search feature to be integrated into a real estate website. This progrom will allow MLS/IDX searching/browsing (searching by MLS #, house variables, etc) and browsing by property location, etc.

I have come accross RETS and have tried to go about it, but wow, maybe MLS/IDX is just some mythical database that doesn't exist? If anyone can help me out here. show some code, point me to a resource, tutorial, something that would be some assistance, I would bow down to them, and mail them one, yes, one ice cold root beer.

View Replies !
Resolve Real IP
I can get the apparent IP from $_SERVER['REMOTE_ADDR']; . However, how can I find the real IP if the user is behind a proxy? I know it must be possible as some "whatismyip" sites do it.

View Replies !
Mysql Real
I found this which I think calls for an indepth brain storming. A very good reading

[edited by: eelixduppy at 1:06 pm (utc) on Sep. 12, 2007]
[edit reason] fixed typo as per request [/edit]

View Replies !
Real-time Output?
I'm a relative PHP newbie, so I apologize if this is a simple question.

Anyway, here's my problem. I'm using a PHP script to pre-render a bunchload of insert files for an HTML page. Right now there's about 1,600, but that number could get much, much higher when the site goes live.

I'll only need to re-render the whole batch once or twice a year (if that) but it's still something I'd like to be able to do in case I have to move the site to a different server, or there's a hard drive crash or etc.

Basically what the script does is grab a whole bunch of information from a database and write the insert file. It does this for every single one.

The problem of course, is that PHP by default does all this server-side, and then sends it to the browser. Because this process takes like ten or twenty minutes to do, the browser times out long before it's finished.

Is there a way to get progressive output with PHP? Or do I need to re-do this in another language like Perl?

View Replies !
Real Length Of Arrays
Sometimes, I want to know how many elements are really in an array (php3).

The count() and sizeof() functions apparently return the number of non-empty array elements, and if you do a while loop checking for empty will stop on the first empty element.

I have been using the following function:
function truecount($theArray) {
if (is_array($theArray)) {
end($theArray);
return key($theArray);
}
}
but if the key is non-numeric, won't that trip me up?
Anyone have a better solution?

View Replies !
Md5 / Sha1 - Any Real Difference?
I use md5 hash with some of my cookies and occassionally a hidden form
field - I know the physical data on my network is insecure (unless being
served via https) but I was wondering if there are any advantages to using
md5 over sha1 or versa vicea... I know md5 gives me a unique 32bit hash
while sha1 I've read is 'secure' (?) and gives a 40bit hash... Since The
technical webpage on sha1 is lengthy and for the most part over my head...
and other than today, I've never heard of it before... I was wondering if
anyone could offer any comments on it...

View Replies !
Real Time Chat
There's anyone out there that can give me a light on real time chat using sockets. I've seen some using push technics but they all hang up after an elapsed amount of time.

View Replies !
Htmlspecialchars/real Escape
I'm creating a BBCode parser, and everything's working but one thing; I need code tags, but I will need to real_escape/htmlspecialchars the post to make sure it isn't malicious. The only problem is if I real_escape with code tags that contain php, the php will be removed. If I specialchars the post with php, I can't have syntax highlighting (or, not easily). How do I get round this?

View Replies !
Real IP Address From Behind Proxy Or NAT
How to get the real IP address of a user, not that of their proxy server or the external NAT address. I was quite sure that this wasn't possible without some kind of process getting the address on the client machine.

I have suggested that these sites could be using Java to get the real IP address, however, I could be wrong and for me the script that I found always returns 127.0.0.1 . This suggests to me that any script attempting to obtain the hosts real IP address infarct rely s on the HTTP-X-FORWARDED-FOR header sent by the proxy server...

View Replies !
Real-time Clock
Where should I start to write a Real-time Clock? I want it be dynamic, not static. I know how to get the time and display it but how do I keep changing it ?

View Replies !
My Real Estate Scripts
I have been writing a real estate agency program and its coming on well but taking longer than I thought. Also I think I am just re-inventing the wheel as I guess like BB scripts there are probably good free ones already writen in php and using mysql ? Can anyone recommend one.? can then continue learning while adapting it to my purposes.

View Replies !

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