{"id":70,"date":"2017-11-02T10:57:02","date_gmt":"2017-11-02T08:57:02","guid":{"rendered":"https:\/\/lyubomir-angelov.com\/?p=70"},"modified":"2017-10-17T23:27:34","modified_gmt":"2017-10-17T20:27:34","slug":"escape-backslash-and-special-char-in-php-command-line","status":"publish","type":"post","link":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/","title":{"rendered":"Escape backslash and special char in PHP &#8211; command line"},"content":{"rendered":"<p>If you ever need to escape special char with a backslash and then to escape the backslash in shell_exec() or exec() PHP functions (<strong>not only<\/strong>).<br \/>\n<!--more--><\/p>\n<p>You will think that <code>\\\\\\%<\/code> will do the work, backslash to escape the percentage and double backslashes to escape the backslash but this will not work.<br \/>\nThe correct way is to again double backslash the double backslashes that escape the backslash which escapes the percentage (LooooL) \ud83d\ude42 so it will look like that <code>\\\\\\\\\\%<\/code> <\/p>\n<p>Something like this in PHP:<\/p>\n<pre class=\"language-php\"><code>\n$percentage = $percentageNum . &#039;\\\\\\\\\\%&#039;;\n$drawText = &quot;,drawtext=text=&#039;&quot; . $percentage . &quot;&#039;:fontcolor=0xffdd00:fontsize=27:font=telegrama_raw:fontfile=&quot; . realpath($this-&gt;config[&#039;videos&#039;][&#039;font_path&#039;]) . &quot;:x=70:y=288:enable=&#039;between(t,0,3)&#039;&quot;;\n$cmd = $ffmpeg[&#039;bin&#039;] . &#039; -y -i &#039; . $videoBlack . &#039; -min_delay 0 -ignore_loop 0 -i &#039; . $animationGif . &#039; -filter_complex &quot;[0][1]overlay=0:0,scale=480x480,setsar=1:1&#039; . $drawText . &#039;&quot; &#039; . $animationVideo;\nshell_exec($cmd);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you ever need to escape special char with a backslash and then to escape the backslash in shell_exec() or exec() PHP functions (not only).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[6,13],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bash","tag-special-chars"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Escape backslash and special char in PHP - command line - Lyubomir Angelov<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Escape backslash and special char in PHP - command line - Lyubomir Angelov\" \/>\n<meta property=\"og:description\" content=\"If you ever need to escape special char with a backslash and then to escape the backslash in shell_exec() or exec() PHP functions (not only).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/\" \/>\n<meta property=\"og:site_name\" content=\"Lyubomir Angelov\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-02T08:57:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-17T20:27:34+00:00\" \/>\n<meta name=\"author\" content=\"Lyubomir\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@angelovcode\" \/>\n<meta name=\"twitter:site\" content=\"@angelovcode\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lyubomir\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/\"},\"author\":{\"name\":\"Lyubomir\",\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92\"},\"headline\":\"Escape backslash and special char in PHP &#8211; command line\",\"datePublished\":\"2017-11-02T08:57:02+00:00\",\"dateModified\":\"2017-10-17T20:27:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/\"},\"wordCount\":92,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92\"},\"keywords\":[\"bash\",\"special chars\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/\",\"url\":\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/\",\"name\":\"Escape backslash and special char in PHP - command line - Lyubomir Angelov\",\"isPartOf\":{\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#website\"},\"datePublished\":\"2017-11-02T08:57:02+00:00\",\"dateModified\":\"2017-10-17T20:27:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lyubomir-angelov.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Escape backslash and special char in PHP &#8211; command line\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#website\",\"url\":\"https:\/\/lyubomir-angelov.com\/blog\/\",\"name\":\"Lyubomir Angelov\",\"description\":\"The life of a Manager\",\"publisher\":{\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/lyubomir-angelov.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92\",\"name\":\"Lyubomir\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f6b8c15868355fa857fad18647aeadd07814e3d9baa72a1c92e718056684fec7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f6b8c15868355fa857fad18647aeadd07814e3d9baa72a1c92e718056684fec7?s=96&d=mm&r=g\",\"caption\":\"Lyubomir\"},\"logo\":{\"@id\":\"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/twitter.com\/angelovcode\"],\"url\":\"https:\/\/lyubomir-angelov.com\/blog\/author\/superfly\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Escape backslash and special char in PHP - command line - Lyubomir Angelov","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/","og_locale":"en_US","og_type":"article","og_title":"Escape backslash and special char in PHP - command line - Lyubomir Angelov","og_description":"If you ever need to escape special char with a backslash and then to escape the backslash in shell_exec() or exec() PHP functions (not only).","og_url":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/","og_site_name":"Lyubomir Angelov","article_published_time":"2017-11-02T08:57:02+00:00","article_modified_time":"2017-10-17T20:27:34+00:00","author":"Lyubomir","twitter_card":"summary_large_image","twitter_creator":"@angelovcode","twitter_site":"@angelovcode","twitter_misc":{"Written by":"Lyubomir","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#article","isPartOf":{"@id":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/"},"author":{"name":"Lyubomir","@id":"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92"},"headline":"Escape backslash and special char in PHP &#8211; command line","datePublished":"2017-11-02T08:57:02+00:00","dateModified":"2017-10-17T20:27:34+00:00","mainEntityOfPage":{"@id":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/"},"wordCount":92,"commentCount":0,"publisher":{"@id":"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92"},"keywords":["bash","special chars"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/","url":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/","name":"Escape backslash and special char in PHP - command line - Lyubomir Angelov","isPartOf":{"@id":"https:\/\/lyubomir-angelov.com\/blog\/#website"},"datePublished":"2017-11-02T08:57:02+00:00","dateModified":"2017-10-17T20:27:34+00:00","breadcrumb":{"@id":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/lyubomir-angelov.com\/blog\/escape-backslash-and-special-char-in-php-command-line\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lyubomir-angelov.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Escape backslash and special char in PHP &#8211; command line"}]},{"@type":"WebSite","@id":"https:\/\/lyubomir-angelov.com\/blog\/#website","url":"https:\/\/lyubomir-angelov.com\/blog\/","name":"Lyubomir Angelov","description":"The life of a Manager","publisher":{"@id":"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lyubomir-angelov.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/5e091f5c2fa79f57d30d482a7ef8cd92","name":"Lyubomir","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f6b8c15868355fa857fad18647aeadd07814e3d9baa72a1c92e718056684fec7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f6b8c15868355fa857fad18647aeadd07814e3d9baa72a1c92e718056684fec7?s=96&d=mm&r=g","caption":"Lyubomir"},"logo":{"@id":"https:\/\/lyubomir-angelov.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/twitter.com\/angelovcode"],"url":"https:\/\/lyubomir-angelov.com\/blog\/author\/superfly\/"}]}},"_links":{"self":[{"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":7,"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/posts\/70\/revisions\/78"}],"wp:attachment":[{"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyubomir-angelov.com\/blog\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}