PHP check if money_format [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a form that asks for money entered and would like to have it formatted correctly with $, commas every 3 places, and no decimals unless applicable. The trouble is that some users enters them correctly while others do not. How do I check in php to see if this number is in the proper format and if it is not, adjust it accordingly. I've already placed the $ to precede the number, just need help with commas and decimal places.
I've heard it's easier to use number_format rather than money_format. Is there a benefit to use one over the other?

"some users enters them correctly while others do not"
Check on input and you're done, just use number_format afterwards to format the number as you like.
To use money_format you need to have your locales properly configured, if you're just using $, number format is easier.

Related

using explode with php and mysql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am doing my project and I am using php and MySQL
My program is reading a data from textarea as a list of people, I use the explode function to separate the list and then I generate a for loop to insert them to MySQL database
till this part I don't have any problems
The problem is when I query the database with a where condition specifying a name from the list it does not recognize it
My question does the explode function change any thing to the names in the list or add any special characters
because I use the same functionality with specific name and it goes smoothly
Thanks in advance
It should not. PHP explode will not change your text and the WHERE query should operate correctly.
Are the characters all utf8 encoded? Check the database and see what you are querying for actually exists the same way you are sending it.
Like the others said, if you can provide us an example of the following it would be great:
Actual textarea input (not exploded).
DB Dump of what is inserted.
Your QUERY to select
Additionally, it could be a space issues, use trim before you insert the data or in your query instead of field = '$a' do a field LIKE '%$a%'
I don't think explode() will modify anything. try to use trim() in your foreach loop before inserting. Might be some characters that can not be seen.

PHP Algorithm and MySQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have an equation that I need to process from a couple MySQL columns. I am just trying to figure out the best way of doing this once I run my SELECT statement to retrieve all the data.
Table - tbl_Spirits
Columns - ID, Volume, Proof
I know how to retrieve all the Data from MySQL, the problem is, is that there may be one record returned or 5. Probably never more then 5. Is there a clean fast method of the equation below in PHP.
This example is if there was 2 records returned.
((Volume1 * Proof1) + (Volume2 * Proof2)) / (Volume1 + Volume2)
Even if you did not show any attempt to solve your problem, I will give it a try. Basically you want to divide the sum of products between the two columns by the sum from one of them. So it should be something like
SELECT
SUM(`Volume`*`Proof`)/SUM(`Volume`)
FROM
`tbl_Spirits`
WHERE
1
and you will need to fill in your WHERE statement to fit your needs
Update: added this sample in sqlfiddle: http://sqlfiddle.com/#!2/0dc417/1/0
you will see that for the two records the value you will get is 4, exactly (2*4+3*4)/(2+3)

PHP - basic phone number validation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I'm trying to validate for UK phone numbers - the specific requirements I have are:
must only consist of digits
the only non-digit characters allowed are space and dash
must begin with a zero
Can anyone suggest a nice and simple regular expression I can use for this?
Try with following regex:
^0([ -]\d+)*\d+$

Prevent special characters like space in PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a field that users can enter whatever hey want, And I would allow them for decoration using special characters. but Now I really face with a big problem!
Special characters are like this: ♥♦☻NAME☻♦♥
And my really problem is 'alt+255' characters. it's like space and there are so many special characters like space. by the way My links are disabled and no one could select it.
There is a mandatory to enter more than only 1 character,
I want to know how to prevent this problem. my exact mean How can I let users enter special characters but still my links are clickable
If you are including the text in URLs then you really have two options. The most common approach is to strip out everything except for letters, numbers, dashes, and underscores (i.e. don't allow any special characters at all). You could use a simple regular expression replacement to do that.
Alternatively, you could allow all special characters, but escape them for use in links. You will find PHP's urlencode() and urldecode() useful for that.

PHP buffer overruns [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Are there any known points to be careful about buffer overruns in PHP? Currently I take an email address from a form, run it through preg_match to check it's only a single address, call the mail function with it, and store another load of form data in a database using PDOStatement::bindValue().
Anything to worry about?
If you are asking if it's possible to write code in PHP that contains buffer overflow vulnerabilities, then the answer is no. You can't have those in PHP, it manages the memory for you and you can't directly alter the memory. The only scenario is that PHP itself has a (security) bug, which you can mitigate by keeping PHP up to date.
In addition to using preg_match to check for proper formatting, I wouldn't do anything with user input without checking its length first. I could probably come up with a 10,000 character string that would pass a simple formatting check.

Categories