FMP Expression | PHP Expression | Result | Notes |
---|---|---|---|
10^2 | pow ( 10 , 2 ) | 100 | |
Abs ( -37 ) | abs ( -37 ) | 37 | |
Ceiling ( 6.1 ) | ceil ( 6.1 ) | 7 | |
Date ( 7 ; 26 ; 2007 ) | date ( "n/j/Y", mktime ( 0, 0, 0, 7, 26, 2007 ) ) | 7/26/2007 | |
Date ( 5 ; 7 ; 2007 ) + 1 | date ("n/j/Y", strtotime ( "5/7/2007 + 1 day" ) ) | 5/8/2007 | This is an example of math with dates. |
Day ( "5/1/2007" ) | date ("j", strtotime ( "5/1/2007" ) ) | 1 | |
DayName ( "5/1/2007" ) | date ("l", strtotime ( "5/1/2007" ) ) | Tuesday | |
DayOfWeek ( "5/1/2007" ) | date ("N", strtotime ( "5/1/2007" ) ) + 1 | 3 | PHP treats Monday as day 1 of the week and FMP treats Sunday as day 1 |
DayOfYear ( "5/1/2007" ) | date ("z", strtotime ( "5/1/2007" ) ) + 1 | 121 | |
Floor ( -6.1 ) | floor ( -6.1 ) | -7 | |
GetAsDate ( "3/1/2007" ) - 1 | date ( "n/j/Y", strtotime ( "3/1/2007 - 1 day" ) ) | 2/28/2007 | This example demonstrates how to find the last day of the month. |
GetAsDate ( "5/1/2007" ) | date ( "n/j/Y", strtotime ( "5/1/2007" ) ) | 5/1/2007 | |
GetAsNumber ( "PLAT-NO.1234" ) | preg_replace ("/[^0-9.-]*/", "", "PLAT-NO.1234") | -.1234 | There is no built-in, elegant way for PHP to emulate FileMaker's string to number conversion, but this regular expression is not too bad and does the job. |
GetAsTime ( "12:34:56" ) | date ( "H:i:s", strtotime ( "12:34:56" ) ) | 12:34:56 | |
GetAsTimestamp ( "5/1/2007 12:34:56" ) | date ( "n/j/Y H:i:s A", strtotime ( "5/1/2007 12:34:56" ) ) | 5/1/2007 12:34:56 PM | |
Hour ( "12:34:56" ) | date ("H", strtotime ( "12:34:56" ) ) | 12 | |
Int ( -6.1 ) | (int) -6.1 | -6 | This PHP example looks weird. This is the syntax for "typecasting", or converting a value from one type to another. Here, I am casting the fractional value from a float (roughly equivalent to FMPs Number data type) to an integer (FMP has no equivalent for the integer type). |
Int ( Random * 100 ) | rand ( 1, 100 ) | 36 | Generate a random integer between 1 and 100 inclusive. |
IsValid ( GetAsDate ( "5/32/2007" ) ) | strtotime ( "5/32/2007" ) ? 1 : 0 | 0 | The strtotime function returns FALSE if a given string can not be converted to a valid date. However, when you echo FALSE in PHP, you get an empty string. FMPs IsValid function returns 0 on failure and 1 on success, so to emulate that behavior I had to append the ternary conditional operator to the expression. |
Left ( "FileMaker Pro Advanced" ; 4 ) | substr ( "FileMaker Pro Advanced", 0, 4 ) | File | |
LeftWords ( "FileMaker Pro Advanced" ; 2 ) | implode ( " ", array_slice ( str_word_count ( "FileMaker Pro Advanced", 1 ), 0, 2 ) ) | FileMaker Pro | I was afraid that I was not going to be able to come up with a PHP version of any of the word based FMP functions, but after some research I discovered the str_word_count() function. Used in conjunction with the array_slice() and implode() functions, it does the job pretty well. The only gray area is that I am not 100% sure that what str_word_count() considers a word is the same thing as what FMP considers a word. |
Length ( "FileMaker Pro Advanced" ) | strlen ( "FileMaker Pro Advanced" ) | 22 | |
Lower ( "FileMaker Pro Advanced" ) | strtolower ( "FileMaker Pro Advanced" ) | filemaker pro advanced | |
Middle ( "FileMaker Pro Advanced" ; 5 ; 4 ) | substr ( "FileMaker Pro Advanced", 4, 4 ) | Make | |
MiddleWords ( "FileMaker Pro Advanced" ; 2 ; 1 ) | implode ( " ", array_slice ( str_word_count ( "FileMaker Pro Advanced", 1 ), 1, 1 ) ) | Pro | (see LeftWords for comments) |
Minute ( "12:34:56" ) | date ("i", strtotime ( "12:34:56" ) ) | 34 | |
Mod ( 3 ; 2 ) | 3 % 2 | 1 | |
Month ( "5/1/2007" ) | date ("n", strtotime ( "5/1/2007" ) ) | 5 | |
MonthName ( "5/1/2007" ) | date ("M", strtotime ( "5/1/2007" ) ) | May | |
PatternCount ( "FileMaker Pro Advanced" ; "a" ) | substr_count ( strtolower ( "FileMaker Pro Advanced" ) , "a" ) | 3 | |
Position ( "FileMaker Pro Advanced" ; "e" ; 4 ; 1 ) | stripos ( "FileMaker Pro Advanced", "e", 4 ) | 4 | - stripos() has no equivalent to the fourth param of the Position function (occurrence). - The offset parameter of stripos() is "between" the letters, not on them. - stripos() returns the position starting from 0, so you have to add 1 to the result to make them match. - stripos() returns FALSE if no match is found, not 0. |
Proper ( "filemaker pro advanced" ) | ucwords ( "filemaker pro advanced" ) | Filemaker Pro Advanced | |
Random | 1 / rand ( 1, 100 ) | .58839604844730164501 | In theory, this PHP expression should return a random number between 0 and 1, just like the Random function in FMP. However, the FMPs Random always returns 20 digits after the decimal, and my PHP expression does not. Truthfully, I usually use the FMP Random function to generate a random integer which the regular PHP rand function is excellent at. See the other Random record for an example. |
Right ( "FileMaker Pro Advanced" ; 4 ) | substr ( "FileMaker Pro Advanced", -4 ) | nced | |
RightWords ( "FileMaker Pro Advanced" ; 2 ) | implode ( " ", array_slice ( str_word_count ( "FileMaker Pro Advanced", 1 ), -2 ) ) | Pro Advanced | (see LeftWords for comments) |
Round ( 3.147 ; 2 ) | round ( 3.147, 2 ) | 3.15 | |
Seconds ( "12:34:56" ) | date ("s", strtotime ( "12:34:56" ) ) | 56 | |
Substitute ( "aaaaa" ; "aa" ; "a" ) | str_replace ( "aa", "a", "aaaaaa" ) | aaa | Notice that both examples take only one pass at the replacement. Therefore, the resulting text can sometimes still contain instances of the search pattern. |
Substitute ( "FileMaker Pro Advanced" ; "a" ; "o" ) | str_replace ( "a", "o", "FileMaker Pro Advanced" ) | FileMoker Pro Advonced | |
Time ( 12 ; 34 ; 56 ) | date ( "H:i:s", mktime ( 12, 34, 56 ) ) | 12:34:56 | |
Timestamp ( Date ( 1 ; 0 ; 2007 ) ; Time ( 12 ; 34 ; 56 ) ) | date ( "n/j/Y H:i:s A", mktime ( 12, 34, 56, 1, 0, 2007 ) ) | 12/31/2006 12:34:56 PM | |
Trim ( " FileMaker Pro Advanced " ) | trim ( " FileMaker Pro Advanced " ) | FileMaker Pro Advanced | |
Truncate ( 1.234 ; 2 ) | (int) ( 1.234 * pow ( 10 , 2 ) ) / pow ( 10 , 2 ) | 1.23 | |
Upper ( "FileMaker Pro Advanced" ) | strtoupper ( "FileMaker Pro Advanced" ) | FILEMAKER PRO ADVANCED | |
WeekOfYear ( "5/1/2007" ) | date ("W", strtotime ( "5/1/2007" ) ) | 18 | |
WordCount ( "FileMaker Pro Advanced" ) | str_word_count ( "FileMaker Pro Advanced" ) | 3 | |
Year ( "5/1/2007" ) | date ("Y", strtotime ( "5/1/2007" ) ) | 2007 |