php - Find position of console escape code in string -


tl;dr how write strpos($haystack, '^[[h^[[2j') in php?

a linux command line app delivers screen-full of data followed console escape code return cursor "home" position in regular loop. access data piped output own script so:

$ ./otherapp | php myscript.php 

it's continuous stream of data use this example non-blocking stream consumption.

now decode output need grab full frame/screen full of data. escape codes shown in nano ^[[h , ^[[2j. easiest way seems detecting these escape codes , using output between them.

how escape codes represented in php string? can use strpos (or mbstring equivalent) detect position?

it seems you're on unix environment. achieve escape codes do, can try echo -en "\033[h" , echo -en "\033[2j", guess should try strpos('\033[h\033[2j', $haystack).

maybe you'll need add backslash ('\\\033[h\\\033{2j').

since \033 means "the byte octal value 33", esc, should work:

strpos("\e[h\e[2j", $haystack) 

you need enclose in double-quotes (") if want php interpret escape sequences special characters.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -