Skip to content

emacs-php/php-runtime.el

This branch is up to date with master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c7f04e8 · Apr 23, 2025

History

65 Commits
Mar 27, 2024
Aug 27, 2017
Sep 13, 2023
Jan 10, 2018
Apr 23, 2025
Aug 26, 2017
Sep 13, 2023
Apr 2, 2023
Apr 2, 2023
Oct 24, 2024
Oct 24, 2024

Repository files navigation

php-runtime.el

This package bridges to PHP: Hypertext Preprocessor.

Requirements

Example

;; Exapmle simple code
(php-runtime-eval "echo strtoupper('apple');")
;;=> "APPLE"

;; Shorthand syntax for a PHP expression
(php-runtime-expr "strtoupper('apple')")
;;=> "APPLE"

;; Execute specific PHP executable
(php-runtime-expr "PHP_VERSION") ; no specific
;;=> "7.1.8"

(let ((php-runtime-php-executable "/usr/bin/php"))
  (php-runtime-expr "PHP_VERSION"))
;;=> "5.6.30"

;; Get numeric value by PHP
(setq php-int-max (string-to-number (php-runtime-expr "PHP_INT_MAX")))

;; Evaluate PHP code with STDIN as a string
(princ (php-runtime-eval "while ($line = trim(fgets(STDIN))) { var_dump($line); }"
                         "apple\nbanana\norange"))

;; Evaluate PHP code with STDIN as a file
(princ (php-runtime-eval "while ($line = trim(fgets(STDIN))) { var_dump($line); }"
                         (cons :file "/etc/hosts")))

Construct PHP expression

(php-runtime-\' "You're wellcome.")
;;=> "'You\\'re wellcome.'"

(let ((a "You'er")
      (b "wellcome"))
  (php-runtime-expr
   (format "implode([%s, %s], ' ')"
           (php-runtime-\' a)
           (php-runtime-\' b))))
;;=> "'You\\'re wellcome.'"