<?php function sanitize($stringToSanitize) { return addslashes(htmlspecialchars($stringToSanitize)); } // You can just use the codes themselves instead of creating a function as: echo addslashes(htmlspecialchars($stringToSanitize)); ?>