tags:

views:

89

answers:

5

For the code below, how could I make $row["title"] and $row["displayurl"] display in capital letters even if they contain lower-case letters?

echo '<td class="sitename1"><a href="http://www.'.$row["url"].'" TARGET="_blank">'.$row["title"].'</a>  <div class="dispurl">'.$row["displayurl"].'</div></td>';
+7  A: 

Use strtoupper()

'.strtoupper($row["title"]).'

Reference: PHP manual on string functions

Pekka
+2  A: 

in CSS:

text-transform: uppercase

in PHP:

string strtoupper ( string $string )
Im0rtality
A: 

See strtoupper(), making your line look like:

echo '<td class="sitename1"><a href="http://www.'.$row["url"].'" TARGET="_blank">'.strtoupper($row["title"]).'</a>  <div class="dispurl">'.strtoupper($row["displayurl"]).'</div></td>';
RobM
+12  A: 

It depends on what you mean by "Capitalizing"

strtoupper("lowercase srting"); // => LOWERCASE STRING
ucfirst("lowercase string"); // => Lowercase string
ucwords("lowercase string"); // => Lowercase String

It could be that this won't work with unicode Strings, but this works with unicode strings to:

mb_convert_case("lowercase string", MB_CASE_TITLE, "UTF-8");
// => Lowercase String
// be aware:
mb_convert_case("UPPERCASE STRING", MB_CASE_TITLE, "UTF-8");
// => Uppercase String

mb_convert_case("lowercase string", MB_CASE_UPPER, "UTF-8");
// => LOWERCASE STRING

There is no direct approach for ucfirst with multibyte characters. PHP-Reference

You can also do this in css:

td.sitename1 a, td.sitename1 div {
  text-transform: uppercase;
} /* Will make 'UPPERCASE STRING' */

td.sitename1 a, td.sitename1 div {
  text-transform: capitalize;
} /* Will make 'Capitalized String' */
jigfox
Nice. You're only missing the CSS ;) - `text-transform:` `capitalize` and `uppercase`
Peter Ajtai
Thanks for this tip!
jigfox
`MB_CASE_TITLE` is not directly analog to `ucwords` because it will lowercase the characters that are not the first ones in the words, while `ucwords` won't.
Artefacto
Thank you, I've update my answer.
jigfox
+1 for completeness.
Pekka
max ways to make the letters capitalize. Really cool +1
srinivas
+2  A: 

Just for completeness, use mb_strtoupper if you're using anything other than ASCII characters.

strtoupper is locale-dependent, and as such may have differernt results in different machines. In fact, it can even have different results for ASCII characters.

Artefacto