Re: Storing and then printing ANSI escape sequences in (and then from)variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Luke Slater a écrit :
> Hi,
> 
> I'm storing ANSI escape sequences in an array, stored like this:
> 
> $connections[$channel][2] = $info['colour'];
> 
> $info['$colour'] would contain something like \033[33m
> 
> Now, my problem is when I try and print it:
> 
> $pstring = $connections[$channel][2] . $connections[$channel][1] . " " .
> $buffer . chr(7);
> 
> It will print as a literal string, actually printing \033[33m to the
> screen, so how do I make it work?
> 
> I'm sure I'm missing something fatally simple here.
> 
> Thanks for your help,
> 
> Luke Slater


Hi,
this depends on your terminal and on your shell. So you have to execute
a shell command (/!\ security). With bash on linux with a color enabled
console, you can use this:

php -r 'print(`echo -e "\033[0mTEST: \033[32mOK\033[0m"`);'

which means that you execute a bash commande (between the 2 backticks
``), and you print the output of this commande.
echo -e      is the bash commande with escape sequences interpretation
enabled

But don't be surprised if it doesn't work, cause it depends on your
terminal (I can't make it run on cygwin for example)

Fred

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux