« Project home page
my little forum
Log in
Register
Search:
Back to the entry by Auge
Post reply
Reply to the message by
Auge
Name:
E-mail:
(optional, won't be displayed directly)
Leave this field empty:
Homepage:
(optional)
Leave this field empty:
Location:
(optional)
Remember me (cookie)
Category:
General
Project organisation
Technics
Design/Themes
Features
Development
Todo
Bugs
German / Deutsch
Spanish / Español
French / Français
Accessibility/UX
Subject:
Formatting help
skip to input
format text bold
[b]bold text[/b]
format text italic
[i]italic text[/i]
insert hyperlink
[link=http://example.com/]link text[/link] / [link]http://example.com/[/link]
set text color
[color=#rgb]colored text[/color]
font size
[size=small]small text[/size]
[size=large]large text[/size]
insert list
[list][*]list item[/list]
insert image
[img]http://example.com/image.jpg[/img]
left: [img=left]http://example.com/image.jpg[/img]
right: [img=right]http://example.com/image.jpg[/img]
thumbnail: [img=thumbnail]http://example.com/image.jpg[/img]
thumbnail left: [img=thumbnail-left]http://example.com/image.jpg[/img]
thumbnail right: [img=thumbnail-right]http://example.com/image.jpg[/img]
upload image
upload image ...
insert TeX code
[tex]TeX code[/tex]
insert code
[inlinecode]code[/inlinecode]
[code]code[/code]
[code=css]code[/code]
[code=html]code[/code]
[code=javascript]code[/code]
[code=perl]code[/code]
[code=php]code[/code]
[code=sql]code[/code]
[code=xml]code[/code]
:-)
;-)
:-P
:-D
:-|
:-(
:yes:
:no:
:ok:
:lol:
:lol2:
:lol3:
:cool:
:surprised:
:angry:
:crying:
:waving:
:confused:
:lookaround:
:clap:
:love:
:tick:
Message:
> Hello > > > > While checking my bookmarks in another forum I therein found a posting, where one proposed a regular expression. A reply contained a link to [link=https://stackoverflow.com/questions/1497885/remove-control-characters-from-php-string#1497928]a stack-overflow-thread[/link]. > > > > > > [code=php]preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', '', $input);[/code] > > > > > > The shown expression addresses the chars 0 to 8 ([inlinecode]\x00-\x08[/inlinecode]), 11 ([inlinecode]\x0B[/inlinecode]), 12 ([inlinecode]\x0C[/inlinecode]), 14 to 31 ([inlinecode]\x0E-\x1F[/inlinecode]) and additionally 127 ([inlinecode]\x7F[/inlinecode]) (is that necessary?). > > Char 127 ([inlinecode]\x7F[/inlinecode]) is the DEL-key. I don't know, if it would break the RSS-feed. > > If not, the resulting function (based on the solution for MLF2, located in [inlinecode]includes/functions.inc.php[/inlinecode]) would look like this: > > [code=php]/** > * filters control characters > * > * @param string $string > * @return string > */ > function filter_control_characters($string) { > # remove the specified control chars (0-8, 11, 12, 14-31) from the string > $string = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $string); > # replace the control char 9 (TAB) with a space > $string = str_replace(chr(9), ' ', $string); > # control chars 10 and 13 (\r, \n) remains untouched > return $string; > }[/code] > > For the MLF1-forum-special-version of Alfie ([inlinecode]functions/funcs.output.php[/inlinecode]) it would be: > > [code=php]/** > * Strips all control characters from output in case of XML output > * > * @param string $string > * @return string $string > */ > function outputXMLclearedString($string) { > # remove the specified control chars (0-8, 11, 12, 14-31) from the string > $string = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/', '', $string); > # replace the control char 9 (TAB) with a space > $string = str_replace(chr(9), ' ', $string); > # control chars 10 and 13 (\r, \n) remains untouched > return $string; > } # End: outputXMLclearedString[/code] > > So the only substantial difference is the name of the function. > > > Looks good! Add a comment to the source what this regex does and why – then I like it. I don’t see a case where 127 could turn up. > > Char 127 (DEL) was never part of our solutions, so I removed it from the regex. > > Tschö, Auge
E-mail notification on reply of this posting
OK - Submit
Preview