I'm writing a function that capitalizes the first letter of a given word. I've done it successfully with the function below. However, it only works on a web page using either -- echo $chars[$i]; -- or -- print $chars[$i]; --.
My problem is I'm trying to use the output in an email that's generated by the script. For this, using "echo" or "print" doesn't work, the function just will not display the output. I did find that if you use -- return $chars[$i]; -- you can get the first letter of the word to appear in the email. But I have no clue how to get the rest of the word to show. What command or bit of code do I need to use?
I've been working on this all night with no answers. I just do not know what to look for.
If you can help, please do. I would truly appreciate it.
function captopic($topic="")
{
$chars = preg_split('//', $topic, -1, PREG_SPLIT_NO_EMPTY);
$char_count=count($chars);
$chars[0] = str_replace("a", "A", $chars[0]);
$chars[0] = str_replace("b", "B", $chars[0]);
$chars[0] = str_replace("c", "C", $chars[0]);
$chars[0] = str_replace("d", "D", $chars[0]);
$chars[0] = str_replace("e", "E", $chars[0]);
$chars[0] = str_replace("f", "F", $chars[0]);
$chars[0] = str_replace("g", "G", $chars[0]);
$chars[0] = str_replace("h", "H", $chars[0]);
$chars[0] = str_replace("i", "I", $chars[0]);
$chars[0] = str_replace("j", "J", $chars[0]);
$chars[0] = str_replace("k", "K", $chars[0]);
$chars[0] = str_replace("l", "L", $chars[0]);
$chars[0] = str_replace("m", "M", $chars[0]);
$chars[0] = str_replace("n", "N", $chars[0]);
$chars[0] = str_replace("o", "O", $chars[0]);
$chars[0] = str_replace("p", "P", $chars[0]);
$chars[0] = str_replace("q", "Q", $chars[0]);
$chars[0] = str_replace("r", "R", $chars[0]);
$chars[0] = str_replace("s", "S", $chars[0]);
$chars[0] = str_replace("t", "T", $chars[0]);
$chars[0] = str_replace("u", "U", $chars[0]);
$chars[0] = str_replace("v", "V", $chars[0]);
$chars[0] = str_replace("w", "W", $chars[0]);
$chars[0] = str_replace("x", "X", $chars[0]);
$chars[0] = str_replace("y", "Y", $chars[0]);
$chars[0] = str_replace("z", "Z", $chars[0]);
for($i=0; $i < $char_count; $i++)
{
return $chars[$i];
}
}
captopic(books);