【问题标题】:PHP CMD - How to Print THIS Special Character (^&|<>)?PHP CMD - 如何打印这个特殊字符(^&|<>)?
【发布时间】:2021-10-31 01:55:30
【问题描述】:

我有一个非常复杂的长文本,我想在 windows 命令提示符下通过 PHP 提取文本。

我的脚本运行良好,但我遇到了这个字符的问题:^&|

例子:

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

*如果我用单引号包裹这个字符,脚本运行良好,但我需要用转义双引号包裹这个字符

如何打印出这些字符?

【问题讨论】:

  • @KJ 我可以通过 php 文件中的块代码打印出这些字符,但我不想为此操作创建新的垃圾文件。

标签: php windows cmd command-line command


【解决方案1】:

终于得到here!的答复

这些特殊字符需要用这个字符^转义

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 >

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 2023-03-12
    相关资源
    最近更新 更多