Text message to send:
'; }
  echo "Your entry: $zip\n";
  echo "Usage: LIBRARY 12345\n\nwhere 12345 is your five-digit ZIP code.";
  if($use_html == 'yes') { echo '
'; } exit(); } $submit_url = 'https://harvester.census.gov/imls/search/library_list.asp'; $submit_vars['Zip'] = $zip; $submit_vars['Distance'] = '50'; $submit_vars['Librarytype'] = 'CE'; $submit_vars['Librarytype'] = 'BR'; $submit_vars['ResultSetNumber'] = '1'; $submit_vars['LibTypes'] = 'CE,BR'; $submit_vars['StateSelectedIndex'] = '0'; $curl = curl_init($submit_url . '?' . http_build_query($submit_vars)); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $rawhtml = curl_exec($curl); $pattern = "/Library_Detail.*(.*)<\/span><\/a>(.*)<\/span>.*(.*)<\/span>/isU"; preg_match_all($pattern, $rawhtml, $library); /* echo '

Pattern matched:

' . print_r($library, TRUE) . '
'; echo '

Raw HTML returned:

'; echo '
' . htmlspecialchars($rawhtml) . '
'; */ if (isset($library[1][0])) { $response = trim($library[1][0]) . "\n" . trim(str_replace(" ", " ", $library[2][0])) . "\n" . trim($library[3][0]); } else { $response = 'Sorry, we could not find any libraries within 50 miles of ' . $zip . '.'; } if($use_html == 'yes') { echo '

Text message to send:

'; }
echo $response;
if($use_html == 'yes') { echo '
'; } exit(); ?>