unset($reader); // elaborate retreived data: // 1. eliminate tags; // 2. shorten description // 3. if the logo does not exist, use default one $dataLen = count($data); $descrKey = 'companydescr'; $logoKey = 'thumb'; // stores the result of controls whether an url corresponds to a resource that exists // It serves to avoid multiple requests to the same url $urlExists = []; $parser0 = new DataParser(); for ($i = 0; $i < $dataLen; $i++) { $text = strip_tags($data[$i][$descrKey]); if (strlen($text) > DESCR_MAX_LENGTH) { $text = trim($parser0->cut($text, DESCR_MAX_LENGTH, " ")) . "…"; } $img = $data[$i]['thumb']; if (empty($img) || $img == "null") { $imgPath = LOGO_STORE . LOGO_DEFAULT; } else { $img = pathinfo($img)['basename']; if (array_key_exists($img, $urlExists)) { $imgPath = LOGO_STORE . ($urlExists[$img] ? $img : LOGO_DEFAULT); echo "{$img} has been already controlled\n"; } else { $header_response = get_headers(LOGO_STORE . $img, 1); // echo $header_response[0] . "\n"; $urlExists[$img] = !strpos($header_response[0], "404"); $imgPath = LOGO_STORE . ($urlExists[$img] ? $img : LOGO_DEFAULT); }
public function testCutLeftWins() { $a = new DataParser(); $this->assertEquals("123", $a->cut("123x5x789", 4, "x")); }