Showing posts with label String. Show all posts
Showing posts with label String. Show all posts

String Prefix 'N' In T-SQL

This is to enforce the string passed as Unicode NCHAR, NVARCHAR or NTEXT datatype, as opposed to CHAR, VARCHAR or TEXT. SQL Server only supports UTF-16 Unicode.

http://databases.aspfaq.com/general/why-do-some-sql-strings-have-an-n-prefix.html
http://databases.aspfaq.com/database/what-datatype-should-i-use-for-my-character-based-database-columns.html

Enforcing Width Of Cell <td> In HTML Table

It is hard to atomically break down long string such as URL to ensure the width in HTML. Here is a solution.

Within the cell or <td> section, cover your contents with a div section which shall include a width style property:

<div style="width:100px">

If that is not good enough, include this into your CSS:

word-wrap: break-word;

Is_numeric() Is Not Good Enough in PHP

It supposes good enough. However, it fails in following circumstances:

1. In some machines number 0 returns false.
2. Unable to detect ‘+.1’ as numeric.
3. When number flagged as string in database, it returns true. Well, it is not in_numeric’s fault since it is designed that way.
4. However, when six digits number is hexadecimal number for color code in HTML, it would for sure stored in database as string, which does cause the problem.

Solutions:
For 1, If (is_numeric($para) || 0==$para))
For 2, no simple solution as good as enough
For 3, no solution
For 4, store hexadecimal number with # in front in database.


http://stackoverflow.com/questions/2774472/php-is-numeric-returns-false-on-0

Date Format of Parameters for SSRS

While SQL Server does accept the date format as string, it is suggested to convert it to datetime data type. This will allow you to use a calendar control as well as avoiding any date format errors that may occur when running your query. Indeed, it does cause minor errors internally. The period, it can be:

t.add_datetime >= @StartDate AND t.add_datetime < DATEADD(D, 1, @EndDate)

The trick here is for general public both dates should be inclusive. Above code indeed includes the time from 0:00:00 of the StartDate to 23:59:59 of the EndDate.


http://www.sqlusa.com/bestpractices/datetimeconversion/

is_numeric() And is_int() in PHP

Both is_numeric() and is_int() will return neither TRUE nor FALSE, but null if parameter is null. Logically, it is correct. Practically, it does make these two functions next to useless. Because we human being would never believe null is numeric. For human being, it is obvious...

To make it useful, we would first consider if parameter is null or not, then if it is numeric. Here is simple way to test these three situations once for all:

if (0!=strlen(trim(@$para)) && is_numeric(@$para)) {...};

Heredoc and Nowdoc in PHP

Heredoc is to double-quoted string. So the inside can be parsed if there is variable. There is bug associated with Heredoc, namely the line with the closing identifier must contain no other characters, except possibly a semicolon (;). Example:

$err = ‘Parse error, unexpected $end in this.php on line xx’;
<<<HEREDOC
This is to show error message “$err” if you put whitespace either at front or end of closing line.
HEREDOC

Nowdocs are to single-quoted strings however. So a nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. This is very useful to parse a large block of embedded dynamic codes. Example:

<<<’NOWDOC’
Within this block, though $err is a variable, the final result would be exactly same as what you are seeing now. The variable “$err” won’t be parsed.
NOWDOC

No escape needed for both methods.

In addition, although you can use any word for heredoc and nowdoc purpose, it is recommended using exactly these words to emphasis the difference as well as the help you to remember what these techniques are called.

http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Labels