16 [-f <file1>] ... [-f <fileN>] [+e[pcre_modifier]] <key1> <value1> [-e] [+s] <key2> <value2> [-s] ...
21 activate regex matching
for keys with optional PCRE modifiers
23 disable regex matching (plain matching)(
default)
25 activate safe php
string replacement
27 disable safe php
string replacement
29 when
using +s, add apostrophe around the
string (
default)
31 when
using +s,
do not add apostrophe around the
string
33 reset flags to defaults
49 while (count($argv) > 0) {
50 $opt = array_shift($argv);
51 if (!$end && $opt ==
'-R') {
57 } elseif (!$end && $opt ==
'+s') {
59 } elseif (!$end && $opt ==
'-s') {
61 } elseif (!$end && $opt ==
'+q') {
63 } elseif (!$end && $opt ==
'-q') {
65 } elseif (!$end && substr($opt, 0, 2) ==
'+e') {
66 $regex = substr($opt, 2);
67 if ($regex ===
false) {
70 } elseif (!$end && $opt ==
'-e') {
72 }
else if (!$end && $opt ==
'--') {
74 } elseif (!$end && $opt ==
'-f') {
75 $file = array_shift($argv);
77 throw new Exception(sprintf(
"Missing file after '-f' option.\n%s", self::replace_usage()));
81 $value = array_shift($argv);
83 throw new Exception(sprintf(
"Missing value for variable '%s'.\n%s", $opt, self::replace_usage()));
89 'php_string' => $php_string,
94 foreach ($files as
$file) {
95 $content = file_get_contents($file);
96 if ($content ===
false) {
97 throw new Exception(sprintf(
"Error reading from file '%s'.", $file));
99 foreach ($vars as $var) {
101 if ($var[
'regex'] ===
false) {
102 $var[
'key'] = preg_quote($var[
'key'],
"/");
104 $modifier = $var[
'regex'];
106 if ($var[
'php_string']) {
107 $var[
'value'] = var_export($var[
'value'],
true);
108 if (!$var[
'quote']) {
109 $var[
'value'] = substr($var[
'value'], 1, -1);
113 $content = preg_replace(
'/' . $var[
'key'] .
'/' . $modifier, $var[
'value'], $content);
114 if ($content ===
false) {
115 throw new Exception(sprintf(
"Error in regex '/%s/'.", $var[
'key']));
118 if (file_put_contents($file, $content) ===
false) {
119 throw new Exception(sprintf(
"Error writing to file '%s'.", $file));
130 [<string1>] [-b] [<string2>] [<string3>] +b [<stringN>]
132 Returns the
string escaped and enclosed between quotes (
").
135 Enable backslash escaping (default)
137 Disable backslash escaping
139 Enable surrounding double-quotes (")(
default)
141 Disable surrounding
double-quotes (
")
148 public static function doublequote($argv)
154 while (count($argv) > 0) {
155 $opt = array_shift($argv);
156 if (!$end && $opt == '+b') {
158 } elseif (!$end && $opt == '-b') {
160 } elseif (!$end && $opt == '+q') {
162 } elseif (!$end && $opt == '-q') {
164 } else if (!$end && $opt == '--') {
169 'backslash' => $backslash,
174 foreach ($strings as $string) {
175 if ($string['backslash']) {
176 $string['value'] = str_replace(array(
180 ) , $string[
'value']);
182 $string[
'value'] = str_replace(array(
186 ) , $string[
'value']);
187 if ($string[
'quote']) {
188 $string[
'value'] =
'"' . $string[
'value'] .
'"';
190 print ($string[
'value'] . PHP_EOL);
201 Returns the
string escaped
for inclusion between apostrophes.
211 while (count($argv) > 0) {
212 $opt = array_shift($argv);
213 if (!$end && $opt ==
'--') {
221 foreach ($strings as $string) {
222 printf(
'%s' . PHP_EOL, pg_escape_string($string[
'value']));
228 $function = array_shift($argv);
229 if ($function === null) {
230 throw new Exception(sprintf(
"Missing function name."));
232 if (!method_exists(__CLASS__, $function)) {
233 throw new Exception(sprintf(
"Function '%s' does not exists.", $function));
235 $function = __CLASS__ .
'::' . $function;
236 return call_user_func($function, $argv);
240 if (basename(__FILE__) == basename($argv[0])) {
static pg_escape_string($argv)
static pg_escape_string_usage()
static doublequote_usage()