replace - How to modify standard commands in PHP -


is possible modify standard commands in php? use ' {{ ', instance, instead of ' echo '.

in practice use ' echo " ' , ' "; ' often, print whole string. example:

echo " <div class='someclass'>   <table id='sometable'>     <tr>       <td> hello </td>       <td> world </td>     </tr>   </table> </div> "; 

as me it's more convenient , code looks more readable ever when use ' echo ' every new line. possible make more pretty, in laravel framework, example.

{{ <div class='someclass'>   <table id='sometable'>     <tr>       <td> hello </td>       <td> world </td>     </tr>   </table> </div> }} 

i tried difine constant:

define ('{{', 'echo "'); define ('}}', '";'); 

but did not work. replacing code using str_replace in 1 variable needed symbols , print it.

$a = str_replace('{{', 'echo "', $somevariablewithallcodeastext); $a = str_replace('}}', '";', $somevariablewithallcodeastext); 

so question is: is possible in general?

you can define function :

function _($html) {     echo $html; } 

then use in code :

_('<h1>hello world !</h1>'); 

you can use :

<?= '<h1>hello worlds !' <?> 

for shorter way.

but in general, won't able this, can see templates engines smarty or twig, parse template code replace {{ echo


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -