- substr: documentation ( source)
- strpos: documentation ( source)
<?php
function getRidOfPrefix($data, $prefix) {
if (strpos($data, $prefix) === 0) {
return substr($data, strlen($prefix));
}
return $data;
}
echo getRidOfPrefix("something", "so") . "\n";
echo getRidOfPrefix("something", "th");