[0-9]+)\"\>Balance sheet(\s*|)\n/i', $content, $sheets);
267 | // print_r($sheets);
268 | if(isset($sheets["selected"]) and $sheets["selected"] == "" && isset($sheets["id"])) {
269 | $address.="&sheetid=". $sheets["id"];
270 | $response=get($address);
271 | $content=$response[0];
272 | }
273 |
274 | print $address;
275 | print "\n";
276 |
277 | print "date: " . $date . "\n";
278 |
279 | $Fund1=detect($content, ["Fund"], 1);
280 | $Fund2=detect($content, ["Fund"], 2);
281 | print "Fund1: " . $Fund1 . "\n";
282 | print "Fund2: " . $Fund2 . "\n";
283 |
284 | $Financial_facilities1=detect($content, ["financial facilities", "Financial facilities received"], 1);
285 | $Financial_facilities2=detect($content, ["financial facilities", "Financial facilities received"], 2);
286 | print "Financial_facilities1: " . $Financial_facilities1 . "\n";
287 | print "Financial_facilities2: " . $Financial_facilities2 . "\n";
288 |
289 | $Evident_fixed_assets1=detect($content, ["Evident fixed assets", "Evident-fixed assets"], 1);
290 | print "Evident_fixed_assets1: " . $Evident_fixed_assets1 . "\n";
291 |
292 | $Accumulated_gain1=detect($content, ["Accumulated (Losses) gain"], 1);
293 | $Accumulated_gain2=detect($content, ["Accumulated (Losses) gain"], 2);
294 | print "Accumulated_gain1: " . $Accumulated_gain1 . "\n";
295 | print "Accumulated_gain2: " . $Accumulated_gain2 . "\n";
296 |
297 | $Equities1=detect($content, ["Equities"], 1);
298 | $Equities2=detect($content, ["Equities"], 2);
299 | print "Equities1: " . $Equities1 . "\n";
300 | print "Equities2: " . $Equities2 . "\n";
301 |
302 | print "---------------------------------------\n";
303 | }
304 | function key_check($name) {
305 | $name=str_replace("(", "\\(", $name);
306 | $name=str_replace(")", "\\)", $name);
307 | return $name;
308 | }
309 | // Maybe useful...
310 | function fa_en_numeric($string) {
311 | return strtr($string, array('۰'=>'0', '۱'=>'1', '۲'=>'2', '۳'=>'3', '۴'=>'4', '۵'=>'5', '۶'=>'6', '۷'=>'7', '۸'=>'8', '۹'=>'9', '٠'=>'0', '١'=>'1', '٢'=>'2', '٣'=>'3', '٤'=>'4', '٥'=>'5', '٦'=>'6', '٧'=>'7', '٨'=>'8', '٩'=>'9'));
312 | }
313 | function number_check($value) {
314 | if($value == null || $value == "") {
315 | print("Error!\n");
316 | return "None";
317 | }
318 | $value=fa_en_numeric($value);
319 | // print "###" . $value[0] . ", " . $value[mb_strlen($value)-1] . "\n";
320 | if($value[0] == "(" && $value[mb_strlen($value)-1] == ")") {
321 | // print "\n====>".$value."\n---->";
322 | $value="-".mb_substr($value, 1, -1);
323 | // print $value."\n";
324 | }
325 | $value=str_replace(",", "", $value);
326 | return $value;
327 | }
328 | function detect($content, $keys, $year=1) {
329 | $name="(";
330 | if(is_array($keys)) {
331 | $length=count($keys);
332 | if($length == 1) {
333 | $name=key_check($keys[0]);
334 | }
335 | else {
336 | foreach($keys as $index=>$key) {
337 | $name.=key_check($key)."|";
338 | // $name.=$key;
339 | // if($index+1 != $length) {
340 | // $name.="|";
341 | // }
342 | }
343 | $name=rtrim($name, "|");
344 | $name.=")";
345 | }
346 | }
347 | else {
348 | $name=key_check($keys);
349 | }
350 | // print $name."\n";
351 | // exit();
352 | $regex1='>\s*'.$name.'\s*<\/span>\s*<\/td>]+>\s*<([^\>]+)>\s*(?[^\<]+)<\/span>';
353 | if($year == 2) {
354 | $regex1.='\s*<\/td>]+>\s*<([^\>]+)>\s*(?[^\<]+)<\/span>';
355 | // print $regex1."\n";
356 | preg_match('/'.$regex1.'/i', $content, $value);
357 | // print_r($value);
358 | if(!isset($value["value2"]) || $value["value2"] == null || $value["value2"] == "") {
359 | $value["value2"]=null;
360 | }
361 | return number_check($value["value2"]);
362 | }
363 | else {
364 | preg_match('/'.$regex1.'/i', $content, $value);
365 | // print $regex1."\n";
366 | // print_r($value);
367 | if(!isset($value["value"]) || $value["value"] == null || $value["value"] == "") {
368 | $value["value"]=null;
369 | }
370 | return number_check($value["value"]);
371 | }
372 | }
373 | foreach($names as $name) {
374 | get("https://global-stock-exchange.com/ReportList.aspx?search&LetterType=-1&AuditorRef=-1&PageNumber=1&Audited&NotAudited&IsNotAudited=false&Childs&Mains&Publisher=false&CompanyState=-1&Category=-1&CompanyType=-1&Consolidatable&NotConsolidatable");
375 | sleep(2);
376 | // print $url.urlencode($name)."\n";
377 | $response=get($url.urlencode($name), $headers, $from.urlencode($name));
378 | $json=json_decode($response[0], true);
379 | // print_r($json);
380 | if(isset($json["Letters"])) {
381 | $items=$json["Letters"];
382 | // print_r($items[0]);
383 | print $name ."\n";
384 | if(isset($items[0])) {
385 | $address="https://global-stock-exchange.com". $items[0]["Url"];
386 | // print $address;
387 | // print "\n";
388 | check($address);
389 | }
390 | else {
391 | print "Error!\n";
392 | }
393 | }
394 | // print_r($response);
395 | // file_put_contents("test-".$index.".html", $response[0]);
396 | sleep(10);
397 | // break;
398 | // exit();
399 | $index++;
400 | }
401 |
--------------------------------------------------------------------------------
| |