You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef HAVE_CONFIG_H
  2. #include "config.h"
  3. #endif
  4. #include "php.h"
  5. #define PHP_MY_EXTENSION_VERSION "1.0"
  6. #define PHP_MY_EXTENSION_EXTNAME "hello"
  7. PHP_FUNCTION(hello_world);
  8. PHP_FUNCTION(hello);
  9. extern zend_module_entry hello_module_entry;
  10. #define phpext_my_extension_ptr &hello_module_entry
  11. static zend_function_entry hello_functions[] = {
  12. PHP_FE(hello_world, NULL)
  13. PHP_FE(hello, NULL)
  14. {NULL, NULL, NULL}
  15. };
  16. zend_module_entry hello_module_entry = {
  17. #if ZEND_MODULE_API_NO >= 20010901
  18. STANDARD_MODULE_HEADER,
  19. #endif
  20. PHP_MY_EXTENSION_EXTNAME,
  21. hello_functions,
  22. NULL,
  23. NULL,
  24. NULL,
  25. NULL,
  26. NULL,
  27. #if ZEND_MODULE_API_NO >= 20010901
  28. PHP_MY_EXTENSION_VERSION,
  29. #endif
  30. STANDARD_MODULE_PROPERTIES
  31. };
  32. ZEND_GET_MODULE(hello)
  33. PHP_FUNCTION(hello_world)
  34. {
  35. RETURN_STRING("Hello, World!", 1);
  36. }
  37. PHP_FUNCTION(hello)
  38. {
  39. char *name;
  40. size_t name_len;
  41. zend_bool *format = 1;
  42. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &name, &name_len, &format) == FAILURE) {
  43. RETURN_NULL();
  44. }
  45. if (format && name_len) {
  46. name = estrndup(name, name_len);
  47. php_strtolower(name, name_len);
  48. *name = toupper(*name);
  49. }
  50. char *out;
  51. size_t out_len = spprintf(&out, 0, "Hello, %s!", name);
  52. RETVAL_STRINGL(out, out_len, 0);
  53. if (format && name_len) {
  54. efree(name);
  55. }
  56. return;
  57. }