Filter based on ctype_print()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have a function that retrieves data from a database and prints it as XML. I have a page that loads the data into simple_xml and outputs it in the browser. Certain data causes simple_xml to display a parse error (I have no control over the data that goes into the database). I've been able to determine which data will cause the problem using the ctype_print() function on the element contents, and replace it with "This remark contains non-printable characters" so that simple_xml doesn't fail, something like this:

$xmlOutput .= '<remark>';
if (ctype_print($remarks['Remark'])) {
  $xmlOutput .= htmlentities($remarks['Remark']);
} else {
  $xmlOutput .= 'This remark contained non-printable characters';
}
$xmlOutput .= '</remark>';

What I really want to do is replace the non-printable character(s) with printable character(s) (maybe a question mark, or a space), but haven't been able to find a function that will do it. Maybe something like:

$xmlOutput .= '<remark>';
$xmlOutput .= ctype_print_replace($remarks['Remark'], '');
$xmlOutput .= '</remark>';

where the function would replace any non-printable characters with the empty string. If something doesn't exist, I could probably write one myself using preg_replace, but would need a regular expression to find non-printable characters; I'm terrible at regular expressions.

Any ideas? Thanks in advance.
Rick
--
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return"
                                             -- Leonardo Da Vinci

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux