Reputation: 37504
I have this simple string:
echo ucwords("<row><cell><chars class='subHeader'><value>how much time do you spend</value></chars></cell></row>");
But its outputting like so:
<row>
<cell>
<chars Class="subHeader">
<value>how Much Time Do You Spend</value>
</chars>
</cell>
</row>
Upvotes: 0
Views: 1063
Reputation: 684
If it's possible, you'll want to change your code to:
echo "<row><cell><chars class='subHeader'><value>" . ucwords("how much time do you spend") . "</value></chars></cell></row>";
Upvotes: 2
Reputation: 198204
As long as your HTML is that simple like in the input, specifically being US-ASCII encoded and not containing any CDATA sections, this might work:
$str = "<row><cell><chars class='subHeader'><value>how much time do you spend</value></chars></cell></row>";
$str = str_replace('>', '> ', $str);
$str = ucwords($str);
$str = str_replace('> ', '>', $str);
echo $str;
This does work because >
is a reserved character in HTML. Adding a space after each will make ucwords
to work as documented. After ucwords
has done it's job, the change is reverted.
However this might bring you into problems if >
sequences existed earlier which will be removed as well. So take care.
Upvotes: 1
Reputation: 324790
Are you sure it's outputting that, and not <row><cell><chars Class='subHeader'><value>how Much ...
, note the uppercase C on Class
. My guess is that ucwords()
operates on space-delimited words.
Upvotes: 0