FORCING CHARACTERS IN A VIEWER TO DISPLAY IN A PARTICULAR CASE - Aug 2nd, 2010


If you want to force characters entered in a field to display as UPPERCASE when rendered a viewer, here’s a quick
solution.

First define a variable before it’s called. (A field called “title” in this example).

For a list page:



<?php $title = htmlspecialchars($record['title']); ?>



Or for a detail page:



<?php $title = ($your_tableRecord['title']); ?>



You can also add modifying code like:



<?php $title = htmlspecialchars($your_tableRecord['title']); ?>





Then when you display the characters AS UPPERCASE you can use this code:



<?php echo strtoupper($title); ?>



This approach will work with strtolower as well if you want to force lower case.

For many complex php functions, you can just wrap the function call around the "value". In this case, it looks like
this:




<?php echo strtoupper(date("D, M jS, Y", strtotime($e_blastRecord['press_release_publish_date']))) ?>



And for cases when it's getting too complicated, you can break the components up into multiple lines and use variables
so it's easier to read:



<?php
$time = strtotime( $e_blastRecord['press_release_publish_date'] );
$date = date("D, M jS, Y", $time);
$uppercaseDate = strtoupper( $date );
echo
$uppercaseDate;
?>



The approaches will also work in an RSS feed if you insert the “display” code inside the appropriate tags (<title>,
<description>, etc.).

There are other strto functions that may prove interesting. They are listed at:

http://us.php.net/manual-lookup.php?pattern=strto

There are also the functions ucwords and ucfirst that are worth checking out to force your output to display Initial
Caps for each word or only the first word in a field.

After defining your variable as above, you could use something like this to force your “title” field to display
Initial Caps:



<?php echo ucfirst(strtolower($title)); ?>



Or this to make each word capitalized:



<?php echo ucwords(strtolower($title)); ?>



If you’d rather implement a CSS solution, try the CSS function text-transform. It comes in 3 flavors Capitalize, which
will capitalize the first letter in each word, lowercase, which forces all characters to lower case, and uppercase,
which forces all characters to upper case. There’s also inherit and none, which is the default.



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service