Contact Jan Thomas Consulting

September 13, 2007

PHP: Special Characters from database into HTML

Filed under: Programming Techniques — jan @ 12:38 am

Reserved HTML characters such as ampersand (&) and greater than(>) can cause problems if they appear as ordinary text in an HTML document. The browser will mistake these reserved characters for markup. Use the php function htmlentities to convert characters such as & to & if this becomes a problem.

Be aware though, some text such as RSS feeds contain HTML markup for formatting purposes. In this case, htmlentities is NOT recommened.

Character encoding can also lead to display problems. To ensure proper display of special characters, pay attention to the character encoding. UTF-8 is the default character encoding for XML. ISO-8859-1 is more commonly used in HMTL. If you use UTF-8 encoding in the HTML document’s head section, the special characters from XML files and RSS will display properly.

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

Word Press Issues: Indents and Paragraphs

Filed under: Programming Techniques, WordPress Techniques — jan @ 12:00 am

In Word Press blogs there are no indents and paragraphs by default. Ordinarily when you hit the <Enter> key you get a single line but not a paragraph. When I was trying to test this, I found that if you hit the <Enter> twice you get a paragraph break.

The indentation is a separate issue.  I was reading that most bloggers don’t indent their paragraphs.  But if you want to indent a paragraph you use the style.css and add

text-indent: 20px;

For my template, posts are defined by the CSS class: storycontent so that’s where I would add the text-indent line to my style.css file.

September 4, 2007

Use php to pass parameters in the url

Filed under: Programming Techniques — jan @ 11:57 am

I want to pass the parameter topic on the url like this:

http://www.cycsf.org/eventdetails.php?topic=1

Here’s how it can be done in php:

if (isset($_GET['topic']))
$topic_id = (get_magic_quotes_gpc()) ? $_GET['topic'] : addslashes($_GET['topic']);
else
$topic_id = ””;

Powered by WordPress