emacs-php / php-runtime.el

PHP-Emacs bridge, call PHP function from Emacs
GNU General Public License v3.0
8 stars 2 forks source link
emacs melpa php

;; 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")))

+END_SRC

*** Construct PHP expression

+BEGIN_SRC emacs-lisp

(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.'"

+END_SRC