Click to See Complete Forum and Search --> : MySQL CREATE FUNCTION


ShrineDesigns
12-03-2005, 07:06 PM
i can't wrap my brain around this, i am sure that the manual is making it look more difficult than it really is lol

i need to create a function in mysql, that is like this (PHP)function substr_count($substr, $str)
{
$count = 0;
$l = strlen($str);
$x = strlen($substr);
$i = 0;

// WHILE i < l
while($i < $l):
// IF (n = LOCATE(substr, str, i)) = 0
if(!preg_match("/" .$substr. "/i", $str, $n, PREG_OFFSET_CAPTURE, $i)):
break;
endif;
// END IF
// i = n + x
$i = $n[0][1] + $x;
// count = count + 1
$count++;
endwhile;
// END WHILE
return $count;
}