How Drupal's CCK already provides a safely formatted cck field for display

Submitted by charles on

Came across an interesting post when investigating some "n/a" text appearing in a CCK node field when not logged in. I was using the code echo content_format('field_description', $field_description[0]); to safely format and output the description field. Not sure exactly why it happens but it turns out that there's no need to actually do it that way as CCK already provides a safe string of that field for outputting to the browser that is already formatted accordingly. This is available in the $node array, in the 'view' value: [field_url] => Array ( [0] => Array ( [url] => http://www.cso.gov.bw/ [title] => [attributes] => [view] => http://www.cso.gov.bw/ ) ) So you only need to print $node->field_url[0]['view']; If you can't do this, you can still do it the other way, it seems by using the following: But why do it again if it's already been done for you? Update: if not using a cck field, say in a custom module and you want to format a field you've fetched from the database, use the functions check_markup or check_plain