How to get standard PHP functions in C?

How can I call PHP functions from my C application?

Example:

include <php.h> int main() { return json_encode(""); // This is a PHP function coming from php.h } 

Note. PHP function collections are very manageable and organized, I just want to have this logic in my C application, everything is organized on demand. This is the beauty that I found in the PHP language.

+7
source share
4 answers

Since I also want my downvote today, I will try to answer this question;)

I do not know if what you ask is possible. But I'm sure of some other things:

  • The result will be really complex , slow, and will lead to numerous "strong" problems with dependencies and portability.
  • You will get a much better answer if you try to explain why , which you are asking, and what goals you want to achieve
  • Most of PHP is implemented in C, so everything you do in PHP can be done in C. In this regard, here is some information about Turing Completeness .
  • Learning C instead of using some of the well-known PHP features will open up new perspectives that will improve your coding skills .
  • You should ask if you really want / should use C, or is it better to use some other higher level language .
  • If you want to decode JSON messages in C, http://www.json.org/ lists many implementations of the C standard you can use. For base64 decoding see. For example, how to encode (decode) base64 in C? .
+8
source

No, you can’t. However, you can β€œextend” PHP with C and you may be able to cook something, but it is not very useful. Why would you want to do that?

+1
source

Since C is faster than PHP and PHP is written in C, I think trying to use PHP functions in C will make your program unnecessarily slow. And I'm sure this is not possible.

+1
source

You could, and actually this is a project that I mean.
What you need to do is get the PHP SPL code and just rewrite it (clean it up a bit), which will be used as a regular C library. I would like to do this someday.

0
source

All Articles