update page now
Laravel Live Japan

Voting

The Note You're Voting On

divinity76 at gmail dot com
4 years ago
if you need to generate Linux arguments even when running on Windows, try

<?php

    /**
     * quote arguments using linux escape rules, regardless of host OS
     * (eg, it will use linux escape rules even when running on Windows)
     *
     * @param string $arg
     * @throws \InvalidArgumentException if argument contains null bytes
     * @return string
     */
    /*public static*/ function linux_escapeshellarg(string $arg): string
    {
        if (false !== strpos($arg, "\x00")) {
            throw new \InvalidArgumentException("argument contains null bytes, it's impossible to escape null bytes!");
        }
        return "'" . strtr($arg, [
            "'" => "'\\''"
        ]) . "'";
    }

<< Back to user notes page

To Top