Wikis & learning

Normalize a short search query

Text entered into a search field often begins or ends with spaces. Trim it before comparing or storing it.

Text entered into a search field often begins or ends with spaces. Trim it before comparing or storing it.

How it works

Apply one transformation at a time. The example lowercases an ASCII word; an international search may require mbstring and language-specific rules.

PHP example

<?php
$raw = '  LaRaVeL  ';
$term = strtolower(trim($raw));
echo '[' . $term . ']';

Expected result

[laravel]

Try a variation

Try a string containing only spaces and inspect what remains between the brackets.