0

I know php code can be rewritten in C. So just like a strpos() function, I want to add my own built-in function (lets assume a function name vinod) in php source code. Is this possible? If yes then let me know the procedure.

Sample function pseudo-code: my function will return str in a heading tag1.

vinod($str)
{
    return <h1>$str</h1>;
}
6
  • 1
    Why do you want to extend the PHP parser? Just write you own functions in PHP... Commented Apr 17, 2015 at 7:10
  • Just why? 1. You would need to write your code in C 2. You would need to re-compile the source code and it would be a HUGE amount of work to add/update all entries in the source code that your function works! Then you can also write your own program language... Commented Apr 17, 2015 at 7:12
  • 1
    github.com/php/php-src Commented Apr 17, 2015 at 7:15
  • Sara's book is a bit out of date now, but it's still the definitive guide to editing the PHP core - amazon.com/Extending-Embedding-PHP-Sara-Golemon/dp/067232704X Commented Apr 17, 2015 at 7:16
  • 3
    @Rizier123, friend I just wants some help. I am not asking you to do my job. Commented Apr 17, 2015 at 7:28

1 Answer 1

3

You can make a PHP C extension, to add your custom C functions to be available as PHP native functions see below:

  1. Why write your own extension?
  2. How do I build my first PHP extension in C
  3. Writing PHP C extensions
  4. A C++ library for developing PHP extensions
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.