Convert manually entered PHP timezone to a "valid" one - php

We have an application which allows users to enter their timezone manually (via a regular text box).
Since I don't think this was a good idea, I was thinking about replacing this mechanism by showing a drop-down list which lists all of the supported PHP timezones (by using DateTimeZone::listIdentifiers()).
However, I am not sure how to convert the user input (like 'GMT', or other timezones listed here: http://php.net/manual/en/timezones.others.php) to a timezone which is listed as a result of the listIdentifiers() function.
Any suggestions?
Thank you!

I'm not sure what you're trying to do. First you're writing that you have a text input and want to replace it with selectbox but finally you want to convert the value from text input? :p
If you have a value from selectbox with proper identifier you can just create a new DateTimeZone object with name as argument like this:
new DateTimeZone($str);
After that you can do anything with it.

Related

How to limit users to ONLY input one specific language in a Text Field?

So I'm having this Text Field that users can input anything based on the languages installed on their keyboard. I'm asked to limit them to only use Arabic. The example is like this: http://epay.sanjesh.org/Payment/Customer.aspx?id=WcAGgjZVzEk=
In that link, you are only allowed to input Arabic language. Even if your keyboard language is set on English, it still writes Arabic.
I was thinking of using lang="ar".
Is that correct? if it is, then how should I use it?!
You cannot change the input language just by setting the lang attribute. But there are tools that can help you. Take a look at this link for example.
Combine the two for the desired effect.

Format multiple SQL columns or do it in php

I have a database with many columns all with year names. Inside of them on every row are numbers with a type of integer. I want them to all have thousand seperators (A dollar sign would be nice but I can add that in easy with php).
-What I have now is the following:
SELECT *, format(`2015`, 0) AS `15`, FROM `FullList`
and that gives me the seperators like 1,000,000. The problem is I would have to do that for every column that seems wrong.
in my php I use this as simply
<div class=\"example\">$".$row[`15`]."</div>
Giving me $1,000,000
I'm hoping to find a good way of doing this in SQL or maybe even PHP so that I don't need to use format on every column.
Databases should not contain formatting because you are storing information in a standard form which can be read by any application regardless of language. I suppose the column is currently of data-type float(11,2) or something similar, which is correct and recommended.
Though it may seem tedious to add a dollar sign in front of every value, displaying a value should be the job of the templating language (in this case PHP) and not the database.
You might want to use PHP's money_format() instead:
http://php.net/money_format

Asking for a date in PHP

When asking for a date in a HTML form, in the past I was using different solutions:
Using 3 different fields for day, month, year
Using a text field, but adding to the label something like "Start date (example: 31-12-2013)"
Using a reverse date, e.g. 2013-12-31
Now I would like to use HTML5, and just have a input type='date'. This should also help users with mobiles.
For some browsers this may offer a date picker, for some just a text fields. But we all know there are different date formats, and sometimes the user's machine is not configured as he/she would expect. For instance, if I enter a date of 3 January 2014 as 03-01-2014 this can be interpreted as 1 March 2014 in other cultures.
What is the best I can do to help users to prevent mistakes? Is there a way to write an example, without knowing in advance what are his/her browser settings? And how do I know that PHP will interpret the date correctly?
Use ISO 8601 (YYYY-MM-DD) + HTML5's pattern and placeholder attributes
An alternative to falling back to javascript datepickers, might be using a validation (regex) pattern as fallback for browsers that don't support the date type:
<input type="date" placeholder="YYYY-MM-DD" name="date" value="" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" required="required">
While support for the date input type is still very limited, the pattern attribute's support is already more widespread. Of course you'll still need to check all submissions server side, but this should give a nice non-javascript solution for client side validation. You can use the placeholder attribute to show the right format, but since it's not supported by older browsers (IE9 and lower) it might be better to display the example outside of the form field.
html5pattern.com has a nice collection of ready-to-use input patterns, including date patterns but other ones as well. The benefit is that you can use the same pattern for your server side validation as well.
Y-m-d is likely the best method, If you use jQuery UI's date picker you can specify the format.
http://jqueryui.com/datepicker/
you can also show an alternative format.
According to dev.w3.org it will supply you with "A valid full-date as defined in [RFC 3339]".
However there is no way to know what the user meant if they enter 1/2/2014, although 2014-02-01 is unambiguous). As others have mentioned, go with a date picker if possible.
The HTML5 date input specification specifies a full-date format equal to: yyyy-mm-dd. You will receive date in this format always.
Follow this link for more information

Storing a User's Signature in MySQL

I need to store user's signature (ie the thing at the bottom of a forum post) and am not sure how to, I could use text to store the html, but I think there are probably better solutions.
I see no sense in this question.
What's so special with this particular field?
Is it the only one field in this database?
if no - why it's only one raised such a question?
Why not to determine first, what field length will suit you, and then choose appropriate field type according to documentation?
A text field is OK for that. You could use a big varchar field also. But you will have to check and inform your user that there is a limit on the size of his/her signature (which is fine).
A text field is probably the best. If you are worried about the "structure" of the signature, you may use the nl2br() function in PHP, which will convert any new line character stored in the field into the HTML <br/>.

[PHP/MySQL]: Is there a way to store text in Rich Text Format in MySQL table?

I have given en Entry Form to the user to input values that are stored in a MySQL table. There is one column called "Project Details", wherein the user can input upto 200 characters and this column is of type "varchar".
Till here everything is fine. The problem starts when the project details contain a number of points that are to be listed on the HTML page as:
(1) .........
(2) .........
(3) .........
It is unsure whether the project details is of one line, one paragraph, a simple text or a numbered list.
Is there any way to save the project details in rich text format in the MySQL table and when PHP shows the page of my website, the text gets listed as it was pasted?
If you want to store something like rich text format, you'll probably want to place it into a BLOB field: http://dev.mysql.com/doc/refman/5.0/en/blob.html which has no actual character set assigned to it
Can I ask though, why you would want to do that? Why not use one of the many rich text editors that convert your information into HTML (like tinyMCE), which from there you can store as-is or pass it through a Html->Textile filter or something similar.
You might want to consider using a simple markup language like Markdown or Textile. These allow you to take natural looking plain text, and then render it as HTML.
Failing that, you could simply display the text verbatim within <pre> tags.
If you are really using RTF, you might need is RTF-to-HTML-Converter, a quick search brought this: http://directory.fsf.org/project/rtf2html/ (untested). Is this what you meant?
What kind of code you store in a MySQL-Database is up to you, but a Varchar is probably not the best field type; you should consider changing it into a Text-field.
I encrypt using base64_encode() and to get I use base64_decode(). Tabs, spaces and special characters are preserved.
$statement->execute(array(':cemail' => $c_email,
':ctel' => $c_tel, ':msg' => base64_encode($c_msg)));
$msg = $rd['texe;];
$msg = base64_decode($msg)
Works perfectly for me
RTF is not the correct way to go because it's not interpreted correctly by webbrowsers.
You should use some markup language like Markdown, the one used here.

Categories