friky.com
← Back to archive

Post

Simple substring-before function in php

2007-08-30 Agustí Pons Original post

function substring_before($haystack, $needle) { if ($i=stripos($haystack, $needle)) {// Needle found, return from start to needle return(substr($haystack, 0, $i)); } else {// Needle not found return $haystack; } }

Really need an explanation ?