Prevention from XSS

What measures should be taken to prevent XSS in a website? Please give me some links/topics to read.

Hi @Statesman.
You can use htmlspecialchars
For example:

<?php
echo htmlspecialchars($_GET['search']);
?>