home  products examples manual  faq support forum  contact news  login store

More Examples:   View Source:   Checking for empty strings

Free Download

All browsers do not display empty strings properly in a table cell. Part of the table cell borders disappear when attempting to display an empty string. What phpLens does is to automatically insert a non-breaking space " " into the cell. If you want to manipulate the values in a cell that may potentially have an empty cell, you have to check for the empty string. This example shows how you go about checking for an empty string.

In this example: If {country} is not entered into the database, display {country} as "unknown".

(e)User ID


What we want is to check if the value in {Country} is a non-breaking space. If it is, we replace the value with "unknown". Otherwise, we display {Country} We have used the ternary conditional operator in PHP for this. Powerlens setting for {country}
     = {Country}=={nbsp} ? "<font color=red>unknown</font>" : {Country} 
The non-breaking space is a special variable in phpLens known as {nbsp}.

Ternary conditional operator
For those of you unfamiliar with the ternary conditional operator, the explanation for this is below:

The ternary conditional operator functions as follows: 
     $first ? $second : $third
If the value of the first subexpression is true (non-zero), then the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value. You can read more on this in's online documentation.

Why we can't use "&nbsp;" in Powerlens
When you use phpLens to generate source code, phpLens uses the semi-colon character ";" to separate fields in phpLens properties. Therefore, you cannot enter a semi-colon in Powerlens.
E.g. You cannot enter the following in Powerlens:
     = {Country}==&nbsp; ? "<font color=red>unknown</font>" : {Country} 
As a workaround, phpLens has a variable called {nbsp} to represent "&nbsp;". In the next version of phpLens, we will make available another variable called {semicolon} which will provide you with another way to handle special characters.
email: (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800