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




Strip Comma From Number


i have a number 1,553.00 i need to remove the comma and store the value? any ideas?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Convert Number To One With A Comma
How can I convert "2000" to "2,000?"

How To Instert Comma Into Number?
I am having users submit large numbers into a form, and when those values are returned to them later I want to have the commas in the correct places. ie. 123456.00 changes to 123,456.00. Is there a function that does this conversion? Also, how would I ensure that the number is always displayed with 2 decimal places, ie. 123 changes to 123.00, but 123.00 remains 123.00.

Strip A Number
I AM getting 111111 as a variable, I want the first 1 of that series. I can not get it to work with substr(), is there anything else I can do?

Comma Seperator
I have numbers retrieved from database which is quite big. Is it possible to give a comma seperator in the sql query or otherwise
how can I format with a thousand comma separator?

Deleting Last Comma
The code below displays pet names like so:

Fido, Bowser, Kittycat, Spot,

and I want to delete only the last comma. I tried 'substr' and 'rtrim' and both of those delete the space and comma between each name, not just the last name as I'd like, so I end up with:
Fido,Bowser,Kittycat,Spot,

How would I delete only the last comma, so that it is this instead?
Fido, Bowser, Kittycat, Spot

Even with trim and substr, I end up with:

Comma Separated Values
What i've done is when the user enters the client list separated by commas..... this works, but I need to know how to warn the user when they have enter the client list with no commas.

Is there some sort of function which does this or is it a regular expression thing??

Seperating An Array With A Comma
I'm trying to seperate the output of an array with a comma. I can't figure out how to eliminate the last comma. Here is my code:

$result = mysql_query($query,$connection) or die (mysql_error());
$fw = fopen("/var/www/html/ecast/windex/graph.html","w");
fwrite($fw, "/ ");
if ($new_rows = mysql_fetch_array($result)){
do{
fwrite($fw, $new_rows[0]);
fwrite($fw, ", ");
}while($new_rows = mysql_fetch_array($result));
}
fwrite($fw, " /");
fclose($fw);
?>
Output: / 85, 86, 87, 89, /
How can I eliminate that last comma?

Removing A Comma From The End Of An Array
I am reading a file into an array using this:

$listFile = "add2db.txt";
if (!($fp = fopen($listFile, "r")))
exit("Unable to open the input file, $listFile.");
$buffer = fread($fp, filesize($listFile));
fclose($fp);

The very last character in that $listFile will always be a comma. What I need to do is remove that last comma (and only that comma) from $buffer before I can continue on. What do I need to do to accomplish this?

Comma Delimited File
I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields but
not numeric fields.

Is there a simple efficient way to parse the fields with comma but also
strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

Re Comma Separated List - Another Question
I can do the match perfectly but what i also need to do is create a third
list of comma separated values that are in both

eg:

List 1 => 1,2,3,4,5,6,7,8,11
List 2 => 1,3,4,5,6,7,10,23

Therefore

List 3 => 1,3,4,5,6,7

How do I populate this third list - I'm really stuck ....

Breaking Up A Comma Seperated List
i have a list seperated by commas: 1. 3. 5. 7. 9 actually is a varible

$members ="1, 3, 5, 7, 9"; what would be the best way to break that up to insert the values into a table in a loop.

Comma Seperated List Comparison
is it possible to compare acomma separated list aginst another

eg comma list 1 => 1,2,3,4,5
comma list 2 => 3,5
can you check that 3 is in both, and 5 is in both, therfore they match?

the comparison is to check that if product a who supplies products 1,2,3,4,5
can be used instead of product b who supplies 3,5 as product a already
supplies them

Exploding Comma Separated In Array
I'm looking to explode the comma separated values in an array like this:

Array ( => 10811 [1] => 7527,7556 )

and then add the exploded value as a new key in the array...like this:

Array ( => 10811 [1] => 7527 [2] => 7556 )

Seperator Instead Of A Comma For Listed Items In DB?
I'm making a recipe database, and need to have DB fields in mySQL that
will have lists of values that would get sent to an array to be worked
on.

I anticipate that at times a comma will need to be used in the value
itself. So, what's a commonly used symbol or something that people tend
to use as a separator of a list that would then be used in the split()
function to send the elements into an array?

How To Check If It's The Last Result And Remove Comma
I am wondering if anyone could help. I have a loop that displays my results and places a comma after each. The problem is that when the last result is displayed, it shows the comma.

Example:
for loop{
echo $row['test'].', ';

}

displays...  test1, test2, test3,

Notice after test3, there is still a comma? How do I remove it and have it display... test1, test2, test3

Comma Separated Text Files
A client has requested that I make a php app which takes an uploaded image, reads the values and enters them into a database. I've made the upload script which works fine, and the script which enters the values into the database, the only thing left now is how do I make PHP read the file and extract the values? The file is a text file, each field comma separated.

How To Remove Last Comma From A Multiple List?
I have a multiple select list in my site where the values are inserted in a database table, in a column named available_country. I enter these values in the db separated with comma. I don't know however how to remove the last comma so it will be something like this:

USA, Europe, Asia

and not:

USA, Europe, Asia,

Here's what I tried but it didn't worked: ...

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.

Regular Expression For Comma-delimited Pairs
I have a textarea form field for inputting (or pasting) pairs of data.

I need a regular expression pattern to validate each line for the following

double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return

The following comes close, but doesn't check for a carriage return at the
end of each line:

^"([0-9]?)+"([,]s?"([A-Za-z0-9]+)")*$

For example the following would return true:

"1","John"
"2","Paul"
"3","George"
"4","Ringo"

Looping Thru Array And Creating Comma Sep String
I'm trying to loop through the elements of an array and create a comma separated string of the values, and then trim off the last comma. Here's the code I have which only displays the last element of the array in the string: PHP Code:

Reading Excel To MySql Or Comma Delimited ...
right direction on how to deal with an xls
flie.

but the only other file I have to work
with is pdf.

I'm not sure, is xls the better of two evils?


Stripping Quotes Out Of A Comma Delimited File?
I have a flat file that I'm trying to stick into a MySQL database. One
record per line, multiple fields per record, and many of them are null
fields which are just double quotes without a space between. It's probably
nothing really major for people who have done this before, but I'm a bit
stumped. The file is comma delimited. Every field is surrounded by double
quotes. I've done quite a bit of searching, on the php site and elsewhere,
but I can't seem to get it to strip the quotes out so I can explode the file
line by line to grab the fields.

Comma Separated List In MySQL Field
say I have a list of categories in a field, and a page that is supposed to pull from the db based on a category. Is there any way I can do a query where it searches the contents of that field for the category in question?

like SELECT FROM table WHERE category = $category  but have it search the category field (the comma separated list for each entry) for the $category var

Seperate Links From Comma Seperated Value In A Databse
I have a value which is $keywords in my database The key words are separated by commas, like:  fun, funny, exciting, weird I want to make each of those keywords link to "link.php" I can only get them all to be one link, how would I make them each into seperate links.

Easy Comma-delimited List To Dropdown Box Converter
I was working on a simple converter when I realized that by not setting the id param of the option tag, it wasn't going to send the value of the dropdown box to my php script. I had this to start with: Code:

URL Strip
Is there a way to get the URL of a page without actually typing it out and then store that in a variable $url?

If so, how can I strip the URL? For example: say the URL is: www.blah.com/ken2k7/page1.php

Say I want to get the ken2k7 part and store that into a variable $user, how would I do that? And the URL won't always be that, it can be www.blah.com/newuser/page2.php

Strip
What would you use to strip beta or of beta.wordpress.com trying to make a tag section for wordpress mu and need to strip out the subdomain from the database. Thank you

Strip / Addslashes
Could somebody please explain to me why

echo addslashes ( stripslashes ( $stuff ) );

does not output the same thing as echo $stuff; ?

Strip- Vs Addslashes
I must have som errors in my understanding of strip- vs addslashes.
I thought that if a user submitted eg a username, like this
username=siv' drop database test; I should addslashes to escape ' and "
and therefore prohibit the evil user to drop/change my database through
sql injection (my example may not be correct, but I believe it points
out that evil user can add sql commands through an input field.

But - I've been reading lots of code lately, and I see that others use
stripslashes insted of addslashes. And my question is why. What did I
miss? Has it something to do with gpc_magic_quotes?

How To Strip Punctuation?
I am writing a routine that places words used in search phrases into a database table. I am using "explode" to spearate each keyword into a separate entry, but I would also like to strip all punctuation. Can anyone point me in the right direction? I've been toying with preg_replace, but I can't get the syntax to work.

Strip Bbcode
I've been trying to piece together a function that can strip bbcode/vBcode from a block of text (ie: posts). I don't want to translate any of it - just remove all instances of [ ] and whatever tags are between them. This is probably a simple string parsing application, but I can't seem to figure out a way to pull it off.

Strip HTML, Byt Allow Some
How can I strip all HTML tags, except a few that I set as allowed? (strip_tags() doesn't work, have to validate attributes and that the tag is closed)Anyone have a function that I might use?

Strip Text For Rss
this should be a simple answer but i cant figure out what to use to strip text for use in rss.

i keep getting errors because of things like "–"

Strip Tags
I am trying to take external content (text description) that could either be raw text, or HTML content - and assign it to a field that will be displayed on my website.

Since I want to present the data on my website, I want to strip the majaority of HTML tags, that control is font, colour, size, underlines etc.

I know that PHP provides strip_tags for this purpose.  The thing is, I want it to keep the carriage returns/newlines, and if possible bullet points - does anyone know how I can achieve this?

Strip Chars From A String?
How do I take all the instances of a charactor out of a string.

I can't find function to do this.

How To Strip All The Characters Besides A-Z And A-z From A Given String?
Hi all, I got a problem stripping out all the characters which does not fall in any of the following category:

1. Capital letters (A-Z)
2. Small letters (a-z)

What To Strip From User Input:
I recently suffered massive bot attacks against my contact page.
Someone sent me over 350 e-mails from my form in less than a couple of
hours. As this form only sends e-mail to an address dedicated for
this purpose, this isn't more than an inconvenience. In re-writing it,
I decided to write better stripslash and strip_tags functions of my
own. I have the function stripping out left and right angle brackets,
and forward and back slashes. I replace these with blanks (I am the
only one that views these e-mails and I think I can figure out what
was meant). That should break most script and malicious html tags.

What else should I watch for and strip? I thought it might be wise to
replace "=" signs with blanks. Should I worry about words like
"query" or "fopen"?

Part of my solution to preventing bot attacks against my form is to
force manual input by varying the name="" values. I have eighteen
different possibilities for each field on the form. I choose which to
use randomly. I check each possibility when processing to see if it
is set and send posters to a 404 page if they post to the wrong or all
possible variables. I also include a random string of 5 digits as an
authorization code in a hidden field. I use mysql database to let the
processing page know what variables and authorization code to expect,
associated with the poster's ip. Use the wrong authorization code and
you go to the 404 page. If your ip doesn't show up on in the
database, you get a "404 page not found." I delete records from the
database after processing, including old, unused entries where someone
left without completely filling out the form. Does anyone see any
reason that won't work to thwart the bots?

Need To Strip The Slashes Out Of Many Variables...
I need to strip the slashes out of many variables being passed between multiple forms. Unfortunately, one of those variables is an array, so the script was choking on the array to string conversion. To work around this, I coded the script to...

(a) copy the array from $_POST into a variable.
(b) set the array in $_POST to an empty string.
(c) strip the slashes from everything in $_POST and copy to a portable array.
(d) copy the variable from (a) into a slot in the portable array from (c).
(e) send the portable array on it's way.

This worked. No errors. The slashes are gone. The variable and array values are moving.

But I'm afraid I'm not experienced enough with PHP to know whether this is a stable/reliable/safe way to handle this situation. Are there easier or better ways to accomplish this using one of PHP's many functions of which I am blissfully unaware?

Here's the code for the function. Thanks in advance for any replies.

function fetch_postvalues() {
$cats = $_POST['cats'];
$_POST['cats'] = ''
$entry_values = get_magic_quotes_gpc()? array_map('stripslashes', $_POST) : $_POST;
$entry_values['cats'] = $cats;
return $entry_values;
}

Query_string Test And Strip.
Could someone give me the topics to look up on php.net, to be able to work
out how to remove stuff added to a query_string?

I wish to check $QUERY_STRING, and remove any user added extras.

Strip Last Character Off String
I have the following string: text, text, text, text,

I need to strip the last comma from it. Is there a function that pops first and last characters from strings... I was also looking at the strpos() function, but not sure how to use it properly to achieve the desired result...

Function To Strip Returns
I'm trying to write a function that will trim and strip new line
character returns from submitted $_POST values. Does this look serviceable?

function trim_data($formdata)
{
foreach ($formdata as $key => $value)
{
$value = preg_replace("(
|
|
| )", "", $value);
$newdata[trim($key)] = trim($value);

}
return $newdata;
}

Strip Links From Html
I want to strip links from various html pages that I enter from a form. I am so far using file_get_contents() to get the info into a string. The part I am confused with is how exactly do I get the link text itself into one string and then the href or url it leads to in another?

Strip Slashes Using This Syntax?
Should be simple question but just want to make sure since i've only used stripslashes in a different manner of output. Here's what I have in mind. This list will be echoed to the browser showing updated information. I'm using mysql_real_escape_string for the insertion of the data and want to strip the slashes for this output:

<?php
 echo "<ul><li>Step 1: stripslashes($step1)</li>
 <li>Step 2: stripslashes($step2)</li>
 <li>Step 3: stripslashes($step3)</li>
 <li>Step 4: stripslashes($step4)</li>
 <li>Details: stripslashes($details)</li>
 <li>Extra Pick #1: stripslashes($extra_pick1)</li>

 <li>Extra Pick #2: stripslashes($extra_pick2)</li>

 <li>Extra Pick #3: stripslashes($extra_pick3)</li>

 <li>Extra Pick #4: stripslashes($extra_pick4)</li>

 </ul><br>
";
?>
It looks funky in my PHP editor in regards to the color coding.

Strip Leading Zero's
I have a start time and an end time (of a given event) stored in my db as varchar. So, a 1.30 start time looks like 01.30 in the db. Obviously this echos out as 01.30. How do I strip the leading zero's off? I'm looking at str_replace, but I caan't get it right.

PHP Socket Strip XML Tags?
I have implemented a socket in PHP 5.1 which sends a command to a 3rd Party server. The server responds with some XML data. However the data I receive has had all of the XML tags removed, so that I get all of the data items concatenated together.

I have used some socket monitors, and I am, absolutely certain that the correct data is being sent buy the server, it is just not being received properly by PHP.

I am using fsockopen ( 127.0.0.1 ) and fgets, but I have also tried fread and it makes no difference. I still only ever get the data part of the XML string without the tags. I have searched the web and not found anything similar.

Does any one know what I might be doing wrong??

Strip Margin From P Tags
I want to be able to strip the MARGIN elements from the <P> tags.
Currently, I use strip tags to remove the <P> elements completely, but have found that this results in a poorer display of the clients data, since its ignoring paragraphs.

What I actually want to do is just ignore the MARGIN settings within the P tags.  Does anyone know how I can achieve this?

PHP Strip Slashes In Contact Form
Hello, I've been using the following code for email submissions on my website but I could never figure out how to get rid of the slashes when apostrophes are used, once the email is sent. I did a search on this forum and read a bit about the "stripslash" command, but I couldn't figure out how to implement it with the script that I'm using.

Strip Tags With Contents N Times
What is the best way to delete tags n times from either the beginning or the
end of a String? For example, to delete "someString1" and "someString2"
along with surrounding <someTag>'s with n=2 and processing direction is from
beginning.

$someBigString="<someTag>someString1</someTag><someTag>someString2</someTag><someTag>someString3</someTag>";

I was thinking about use preg_replace() to replace "/</tag><tag/" with ""
but wasn't sure how, especially about the n times and direction of
processing.

Strip Html Tags ATTRIBUTES With Reg Exp
I want to strip html attribute within a tag. e.g.:

<td class="blah" colspan="2" bgcolor="#ffffff">blah</td>

And I want to leave the 'colspan="2"' intact. result after stripping with reg exp:

<td colspan="2">blah</td>


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