Abaij
Abaij

Reputation: 873

How to append angular data into php function?

I wonder if it is possible to append angular data into a php function. For example:

<li ng-repeat='item in items'><?php echo formatPeriode("{{ item.period }}") ?></li>

And here is the function in php

function formatPeriode($period){
   $year = substr($period, 0, 4);
   $month = substr($period, 4, 2);

   return $month . ' ' . $year;
}

I know it looks awkward and it's not working anyway. But somehow I need a solution for it.

Upvotes: 0

Views: 53

Answers (1)

As @catcon said, no you can't because the PHP code is evaluated first at the server-side, then at the client-side the javascript. A simple format function can be written in angular pretty easily, for working with dates, check out the moment libary, it has a long list of tools for such.

Upvotes: 3

Related Questions