/** * 获取每一页中的产品名称和url3 * @param $pageUrl */ function getProductUrls($pageUrl, $brandsArray, $keyword, $withoutFilementKeywordXMLName) { ob_start(); //打开输出控制缓冲 ob_end_flush(); //输出缓冲区内容并关闭缓冲 ob_implicit_flush(1); //立即输出 $xmlFileName = 'xml/' . $withoutFilementKeywordXMLName . '.xml'; $html = file_get_html($pageUrl); $ulsdiv = $html->find('.s-result-item'); //获取ul // $productUrls = array(); $index = 0; foreach ($ulsdiv as $li) { $title = $li->find('h2', 0)->plaintext; $productUrl = $li->find('a', 0)->href; $brand = trim($li->find('.a-color-secondary', 1)->plaintext); echo $brand . '-----' . $title . '<br/>'; //存在关键词则认为是打印材料,添加到对应品牌xml文件,否则添加到丢弃文件 if (containsKeyword($title, $keyword)) { //品牌存在,则说明该品牌的xml文件已经存在,直接将该产品添加到对应的xml文件中,否则新建品牌xml文件 if (in_array($brand, $brandsArray)) { addToXML($brand, $brand, $title, $productUrl); } else { createXML($brand, $brand, $title, $productUrl); $brandsArray[$brand] = $brand; } } else { if (file_exists($xmlFileName)) { addToXML($withoutFilementKeywordXMLName, $brand, $title, $productUrl); } else { createXML($withoutFilementKeywordXMLName, $brand, $title, $productUrl); } } // $productUrls[$index] = $productUrl; sleep(1); ob_flush(); //输出缓冲区中的内容 flush(); //刷新输出缓冲 } return $brandsArray; }
so as to assign each msg to the appropriate user */ // include the configs / constants for the API connection require_once "config/api.php"; //include the classes for recording outbound messages to database require_once "classes/connection.php"; //include format checking function and notification module require_once "classes/formatting.php"; //pull in the list of existing keywords from keywords table $mysqli = openConnection(); $keyword_array = getAllKeywordArray($mysqli); //we set the default assignment of msgs to admin account $assoc_user = "******"; //we match the inbound msg to the appropriate user by keyword foreach ($keyword_array as $keyword => $user_name) { //we check for each $keyword if the $msg contains it if (containsKeyword($msg, $keyword)) { $assoc_user = $user_name; //we send the autoreply if it is not null $autoreply = getAutoReply($mysqli, $keyword); if (!is_null($autoreply['text'])) { //we setup the necessary fields for the API call $api_fields = array('from' => '6590249973', 'to' => array($sender), 'text' => $autoreply['text']); $api_result = APISendSMS($api_fields); $json_result = json_decode($api_result, true); //we log the SMS as an outbound message in the database $outbound_data = array('api_ref_id' => $json_result['bulkId'], 'title' => 'Auto-Reply [' . $keyword . ']', 'from' => '6590249973', 'to' => implode(', ', $api_fields['to']), 'text' => $autoreply['text'], 'status' => $json_result['messages'][0]['status']['groupName'], 'credits_used' => $autoreply['num_msg']); //enter details of outbound msg into outbound table and deduct appropriate user credits uploadOutboundInfo($mysqli, $outbound_data); subtractUserCredits($mysqli, $outbound_data['credits_used']); } break;