preg match - return shell_exec then preg_match -
here's pretty weird:
$txt = '/some/dir/some/file.txt'; $content = shell_exec('cat "'.$txt.'"');
then:
preg_match_all("![some regex]!", $content, $matches);
but preg_match returns nothing/false since $content "seems" empty (while it's txt file being filled infos: wget output of download in progress).
weird thing is, if do:
echo $content; exit;
it shows current content of txt file. when f5/refresh, content accurately updated , print again. preg_match still can't parse it...
$content = shell_exec('cat "'.$txt.'"' 2>&1);
isn't doing better.
nb: path file correct, chmod correct, etc...
i tried following:
$content = file_get_contents(dirname(__file__).'/'.$txt, true);
or
$ch_txt = curl_init(); curl_setopt($ch_txt, curlopt_url, dirname(__file__).'/'.$txt); curl_setopt($ch_txt, curlopt_returntransfer, 1); curl_setopt($ch_txt, curlopt_followlocation, 1); $content = curl_exec($ch_txt); curl_close($ch_txt);
and same behaviour goes on!
i've never seen funny.
additionnal info:
the regex is:
preg_match_all("!([0-9a-za-z]+)([ \.]+)([0-9]+)% ([0-9\.a-za-z]+) ([0-9a-za-z]+)!", $content, $matches);
the file content like:
323600k .......... .......... .......... .......... .......... 49% 114k 36m48s 323650k .......... .......... .......... .......... .......... 49% 249k 36m47s 323700k .......... .......... .......... .......... .......... 49% 116k 36m47s 323750k .......... .......... .......... .......... .......... 49% 242k 36m47s 323800k .......... .......... .......... .......... .......... 49% 114k 36m46s 323850k .......... .......... .......... .......... .......... 49% 237k 36m46s
output of this:
system("wget '".$file_to_download."' --load-cookies=".$directory."cookie.txt --output-document='".$directory.$new_directory."/".$output."' -p ".$directory." --output-file='".$directory.$output.".txt' -b >/dev/null 2>&1");
preg_match_all("!([0-9a-za-z]+)([ \.]+)([0-9]+)%([ ]+)([0-9\.a-za-z]+) ([0-9a-za-z]+)!", $content, $matches);
Comments
Post a Comment