escaping

Replace characters with HTML entities in java

孤者浪人 提交于 2019-12-17 14:53:17
问题 I want to replace certain characters with their respective HTML entities in an HTML response inside a filter. Characters include < , > , & . I can't use replaceAll() as it will replace all characters, even those that are part of HTML tags. What is the best approach for doing so? 回答1: From java you may try, Apache Commons Lang (legacy v2) StringEscapeUtils.escapeHtml(). or with commons-lang3: StringEscapeUtils.escapeHtml4(). Please note this also converts à to à & such 回答2: If you're using a

windows C system call with spaces in command

隐身守侯 提交于 2019-12-17 12:43:43
问题 I cannot make system calls with spaces in the names and parameters. For example: system("c:\\program files\\something\\example.exe c:\\my files\\example.txt"); I have tried escaping in every way I know how, and NOTHING works. I have tried: system("\"c:\\program files\\something\\example.exe\" \"c:\\my files\\example.txt\""); and system("c:\\program^ files\\something\\example.exe c:\\my^ files\\example.txt"); Neither work. I still get 'c:\program' is not a recongnised internal or external

how to unescape XML in java

房东的猫 提交于 2019-12-17 10:59:03
问题 I need to unescape a xml string containing escaped XML tags: < > & etc... I did find some libs that can perform this task, but i'd rather use a single method that can perform this task. Can someone help? cheers, Bas Hendriks 回答1: StringEscapeUtils.unescapeXml(xml) (commons-lang, download) 回答2: Here's a simple method to unescape XML. It handles the predefined XML entities and decimal numerical entities (&#nnnn;). Modifying it to handle hex entities (&#xhhhh;) should be simple. public static

Javascript - Replacing the escape character in a string literal

和自甴很熟 提交于 2019-12-17 10:54:25
问题 I am trying to replace the backslash (escape) character in a Javascript string literal. I need to replace it with a double backslash so that I can then do a redirect: var newpath = 'file:///C:\funstuff\buildtools\viewer.html'.replace(/\\/g,"\\"); window.location = newpath; However, it seems to have no result. I don't have the option of properly escaping the backslashes before they are handled by Javascript. How can I replace (\) with (\\) so that Javascript will be happy? Thanks, Derek 回答1:

How to match a single quote in sed

本小妞迷上赌 提交于 2019-12-17 10:47:08
问题 How to match a single quote in sed if the expression is enclosed in single quotes: sed -e '...' For example need to match this text: 'foo' 回答1: You can either use: "texta'textb" (APOSTROPHE inside QUOTATION MARKs) or 'texta'\''textb' (APOSTROPHE text APOSTROPHE, then REVERSE SOLIDUS, APOSTROPHE, then APOSTROPHE more text APOSTROPHE) I used unicode character names. REVERSE SOLIDUS is more commonly known as backslash. In the latter case, you close your apostrophe, then shell-quote your

HTML,PHP - Escape '<' and '>' symbols while echoing

家住魔仙堡 提交于 2019-12-17 09:57:10
问题 I want to print following text as it is: echo "<label> AAAAA"; But it is just showing 'AAAAA' as output. How can I escape '<' and '>' symbol. 回答1: Use htmlspecialchars. <?php echo htmlspecialchars("abc & < >"); ?> 回答2: echo htmlentities("<label> AAAAA"); 回答3: <?php $string = "<label> AAAAA"; //whatever you want echo htmlspecialchars($string); ?> refrence htmlspecialchars 回答4: Use the htmlentities() function to convert into a plain text string. <?php echo htmlentities("<label> AAAAA"); ?> 回答5:

Escape sequence \f - form feed - what exactly is it?

流过昼夜 提交于 2019-12-17 08:54:36
问题 \f is said to be the form feed. \t is a tab, \a is a beep, \n is a newline. What exactly is a form feed - \f ? The following program #include <iostream> int main() { std::cout << "hello\fgoodbye" << std::endl; } prints hello then a female sign (an upside down holy hand grenade:) and then goodbye all on one line. 回答1: It skips to the start of the next page. (Applies mostly to terminals where the output device is a printer rather than a VDU.) 回答2: From wiki page 12 (form feed, \f, ^L), to cause

How to properly escape characters in regexp

血红的双手。 提交于 2019-12-17 07:31:37
问题 I want to do a string search inside a string. Simply saying MySTR.search(Needle) . The problem occurs when this needle string contains special regex characters like *,+ and so on. It fails with error invalid quantifier . I have browsed the web and found out that string can be escaped with \Q some string \E . However, this does not always produce the desired behavior. For example: var sNeedle = '*Stars!*'; var sMySTR = 'The contents of this string have no importance'; sMySTR.search('\Q' +

How to properly escape characters in regexp

强颜欢笑 提交于 2019-12-17 07:31:10
问题 I want to do a string search inside a string. Simply saying MySTR.search(Needle) . The problem occurs when this needle string contains special regex characters like *,+ and so on. It fails with error invalid quantifier . I have browsed the web and found out that string can be escaped with \Q some string \E . However, this does not always produce the desired behavior. For example: var sNeedle = '*Stars!*'; var sMySTR = 'The contents of this string have no importance'; sMySTR.search('\Q' +

mysql_escape_string VS mysql_real_escape_string

妖精的绣舞 提交于 2019-12-17 07:11:34
问题 So this is something we all should know about, and played on my mind when I first seen it.. I know that mysql_escape_string is deprecated from 5.3 but what was the actual difference in mysql_real_escape_string . What I thought was that mysql_real_escape_string is the exact same as mysql_escape_string apart from mysql_real_escape_string takes a second argument for the mysql resource. so then I thought well surly there must be some difference as to how strings are handled because there would