Phazor
A quicker PHP syntax similar to Razor Web Pages.
${ $title = "I love fruit"; $isFruit = true; } $(ucwords($title)) $title. $if ($isFruit) { It sure is great! }
Install Phazor with NPM npm i phazor -g
.
Run the compiler "phazor sourceFolder destinationFolder
" from the parent directory.
Links
Overview
Add PHP code using the $
symbol.
${ -php- }
Code Blocks - ${ $message = "I like fruit."; }
Compiles to:
$variable
Inline Expressions - $message
Compiles to:
<?php echo $message; ?>
For complex expressions use parenthesis - $()
.
$($cost * 2)
Compiles to:
<?php echo $cost * 2; ?>
$statement ( -parameters- ) { -php- }
Statements - $if ($condition == true) { $message}
Compiles to:
<?php if ($condition == true) { ?> <?php echo $message; ?><?php } ?>
/* -comment- */
Comments - Comments work the same as multiline php comments.
${ /* Set the price */ $cost = "$1.99";}Buy Fruit/* How much the fruit will cost */That fruit will cost you $cost each.
$$
Escape Entity - Escape "$" in HTML.
That fruit will cost you $$1.99 each.
Compiles to:
That fruit will cost you $1.99 each.
Basic Example
Install Phazor with NPM npm i phazor -g
.
Create a folder.
Create a .ph file inside the folder:
${ $title = 'Fruit for Sale'; $fruits = array('strawberries' => 'red', 'oranges' => 'orange', 'pineapples' => 'yellow', 'kiwis' => 'green', 'blueberries' => 'blue', 'grapes' => 'purple'); } $title. $title $foreach ($fruits as $fruit => $color) { $(ucwords($fruit)) $if ($color == "green") { - Meh. } else if($color == "orange") { - Yum! } } All these fruits together will cost $$100.
Run the compiler "phazor sourceFolder destinationFolder
" from the parent directory.
Phazor outputs the following .php file into the destination folder:
<?php $title = 'Fruit for Sale'; $fruits = array('strawberries' => 'red', 'oranges' => 'orange', 'pineapples' => 'yellow', 'kiwis' => 'green', 'blueberries' => 'blue', 'grapes' => 'purple'); ?> <?php echo $title; ?>. <?php echo $title; ?> <?php foreach ($fruits as $fruit => $color) { ?> <?php echo ucwords($fruit); ?> <?php if ($color == "green") { ?> - Meh. <?php } else if($color == "orange") { ?> - Yum! <?php } ?> <?php } ?> All these fruits together will cost $100.
Which renders in the browser:
Fruit for Sale
- Strawberries
- Oranges - Yum!
- Pineapples
- Kiwis - Meh.
- Blueberries
- Grapes
All these fruits together will cost $100.