0

I have a very complicated long text, and I want to extract the text via PHP in the windows command prompt.

My script runs fine, but I'm having trouble with this character: ^&|<>

Example:

D:\>php -r "echo 'Hello!';"
Hello!

D:\>php -r "echo \"Hello!\";"
Hello!

D:\>php -r "echo '^';" // Fine
D:\>php -r "echo \"^\";" // Error: without any error message
D:\>php -r "echo \"\^\";" // Error
PHP Parse error:  syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in Command line code on line 1

Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in Command line code on line 1

*The script runs fine if I wrap this character with single quotes, But I need to wrap this character with escaped double quotes

How to print out these characters?

  • @KJ I can print out those characters via block code in a php file, but I don't want to create a new junk file for this operation. – Eva Silviana Sep 01 '21 at 15:07

1 Answers1

0

Finally I got answer from here!

These special characters need to escape with this character ^

D:\>php -r "echo \"Print out ^^\";"
Print out ^

D:\>php -r "echo \"Print out ^&\";"
Print out &

D:\>php -r "echo \"Print out ^|\";"
Print out |

D:\>php -r "echo \"Print out ^<\";"
Print out <

D:\>php -r "echo \"Print out ^>\";"
Print out >

Thank you!