Esempio n. 1
0
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
$config = (require_once __DIR__ . '/../config.php');
$tas = new \Trivago\Tas\Tas($config);
$searchTerm = isset($_GET['query']) ? $_GET['query'] : '';
$locations = [];
if (!empty($searchTerm)) {
    $locations = $tas->getLocations(new \Trivago\Tas\Request\LocationsRequest($searchTerm));
}
/**
 * Replaces highlighted terms with corret HTML.
 *
 * Example: 'Hotel {Berlin}' becomes 'Hotel <strong>Berlin</strong>'
 *
 * @param string $name
 *
 * @return string
 */
function highlight_search_term($name)
{
    return preg_replace_callback('/(\\{[^\\}]*\\})/', function ($match) {
        $name = substr($match[0], 1, strlen($match[0]) - 2);
        return '<strong>' . $name . '</strong>';