I\'m tempted by Automator.app\'s ability to create contextual services in Mac OS X Snow Leopard. I would like to create some keyboard accessible shortcuts to manipulate text
dbr's solution above is excellent, but I found that it didn't work for me, perhaps due to a later change in the shell, php, or OS version (I'm using OS X 10.8). After a lot of head-scratching I found that the answer is to quote the heredoc marker.
A useful addition is to use the appropriate syntax to pass the arguments through to the php script. Putting all that together, I'm using:
php -- "$@" <<'EOF'
EOF