function _views_data_export_xml_tag_clean in Views data export 7.4
Same name and namespace in other branches
- 6.3 theme/views_data_export.theme.inc \_views_data_export_xml_tag_clean()
- 6 theme/views_data_export.theme.inc \_views_data_export_xml_tag_clean()
- 6.2 theme/views_data_export.theme.inc \_views_data_export_xml_tag_clean()
- 7 theme/views_data_export.theme.inc \_views_data_export_xml_tag_clean()
- 7.3 theme/views_data_export.theme.inc \_views_data_export_xml_tag_clean()
Returns a valid XML tag formed from the given input.
Parameters
$tag The string that should be made into a valid XML tag.:
Return value
The valid XML tag or an empty string if the string contained no valid XML tag characters.
4 calls to _views_data_export_xml_tag_clean()
- template_preprocess_views_data_export_xml_body in theme/
views_data_export.theme.inc - Preprocess xml output template.
- template_preprocess_views_data_export_xml_footer in theme/
views_data_export.theme.inc - Preprocess xml output template.
- template_preprocess_views_data_export_xml_header in theme/
views_data_export.theme.inc - Preprocess xml output template.
- XMLExportViewsDataExportTests::testCustomiseXMLNodes in tests/
xml_export.test - Test to ensure that XML nodes names can be manually specified.
File
- theme/
views_data_export.theme.inc, line 447 - Theme related functions for processing our output style plugins.
Code
function _views_data_export_xml_tag_clean($tag) {
// This regex matches characters that are not valid in XML tags, and the
// unicode ones that are. We don't bother with unicode, because it would so
// the preg_replace down a lot.
static $invalid_tag_chars_regex = '#[^\\:A-Za-z_\\-.0-9]+#';
// These characters are not valid at the start of an XML tag:
static $invalid_start_chars = '-.0123456789';
// Convert invalid chars to '-':
$tag = preg_replace($invalid_tag_chars_regex, '-', $tag);
// Need to trim invalid characters from the start of the string:
$tag = ltrim($tag, $invalid_start_chars);
// As a last line of defense, if we've stripped out everything, set it to
// something.
if (empty($tag)) {
$tag = 'invalid-tag-name';
}
return $tag;
}