0

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.

2
  • Angular is javascript, javascript is interpreted at client-side, not server-side (where PHP lives), that why it doesn't work. Commented Apr 2, 2019 at 7:38
  • yes I agree with you. I just wonder how to append angular data into php function (if possible). I actually can make it using angular filter or maybe as pointed out by @Benjamin using momentjs Commented Apr 2, 2019 at 7:54

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.