OK, I have been beating my head over the desk for a while now, and am stuck with a problem that probably has a simple solution, but I can't grasp it.
First the code:
// Lower case the search string to find matches regardless of case
$stringtoreplace = strtolower("jon");
// I want to bold face the search criteria and use that as my replacement
$replacestring = "<B>".$stringtoreplace."</B>";
// Lower case the search string to find matches regardless of case
$string = strtolower("Jones");
// Use str_replace to make the switch
$replacelastname = str_replace($stringtoreplace, $replacestring, $string);
// Now, uppercase the first letter of the result.
$replacelastname = ucfirst($replacelastname);
// Echo the output
echo $replacelastname;
I have commented it to explain my thought process.
OK, simple enough right?
Here's the problem... This works fine (and capitalizes the output properly) if you change the "jon" (in the $stringtoreplace variable) to "one" for example, but if that variable has the first letter, it screws up. ONE THING TO NOTE is if I use strtoupper, it caps the entire wod regardless like it should, but I only want the first letter capped....
I think the problem is because of the appended BOLD tag (which essentially removes the whitespace from the front of the word), but it shouldn't matter, because even the bold tags become part fo the string.
Is there an easier way to do this? Your help would be greatly appreciated.