I am having some trouble with a script I have been writing. It worked out fine the first 10 or so times I executed it but now I get this error: Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16 bytes) [...] in line 25.
Weird thing is that all the script is really doing is take a string, chop it up into a char array and setting the first char in the array to uppercase (to avoid inconsistencies in our database). I just don't know why I get the error now and not the first half an hour I used it.
I have contacted our host but they tell me that I shouldn't exceed the memory limit (duh!) and that they cannot help. I just have this feeling that this is not my fault this time? How can the script exceed 16 mb when all it does is creating some more string and array variables?
Code here:
Weird thing is that all the script is really doing is take a string, chop it up into a char array and setting the first char in the array to uppercase (to avoid inconsistencies in our database). I just don't know why I get the error now and not the first half an hour I used it.
I have contacted our host but they tell me that I shouldn't exceed the memory limit (duh!) and that they cannot help. I just have this feeling that this is not my fault this time? How can the script exceed 16 mb when all it does is creating some more string and array variables?
Code here:
PHP:
<?php
function stringtoarray($string){
$len = strlen($string);
$cur = 0;
$characterarray = array();
while($cur < $len){
$char = $string{$cur};
array_push($characterarray,$char);
$cur = $cur + 1;
}
return $character_array;
}
//_______________________________________________________________________________________//
function correct_lowerc_error($string){
$char_array = stringtoarray($string);
$char_array[0] = strtoupper($char_array[0]);
$formatted_string = implode('', $char_array);
return $formatted_string;
}
//_______________________________________________________________________________________//
function words_to_upper($string){
$string_array = explode(" ", $string);
$i = 0;
while($i <= sizeof($string_array)){
$string_array[$i] = correct_lowerc_error($string_array[$i]);
$i++;
}
$formatted_string = implode(" ", $string_array);
return $formatted_string;
}
$string = 'vellensbyvejen strandberg';
$formatted_string = words_to_upper($string);
echo $formatted_string;
?>