What is the recommended way to escape HTML symbols in plain Java?

StringEscapeUtils from Apache Commons Lang: import static org.apache.commons.lang.StringEscapeUtils.escapeHtml; // … String source = “The less than sign (<) and ampersand (&) must be escaped before using them in HTML”; String escaped = escapeHtml(source); For version 3: import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; // … String escaped = escapeHtml4(source);

How do I properly escape quotes inside HTML attributes?

&quot; is the correct way, the third of your tests: <option value=”&quot;asd”>test</option> You can see this working below, or on jsFiddle. alert($(“option”)[0].value); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <select> <option value=”&quot;asd”>Test</option> </select> Alternatively, you can delimit the attribute value with single quotes: <option value=””asd”>test</option>

How to execute a bash command stored as a string with quotes and asterisk [duplicate]

Have you tried: eval $cmd For the follow-on question of how to escape * since it has special meaning when it’s naked or in double quoted strings: use single quotes. MYSQL=’mysql AMORE -u username -ppassword -h localhost -e’ QUERY=”SELECT “‘*'” FROM amoreconfig” ;# <– “double”‘single'”double” eval $MYSQL “‘$QUERY'” Bonus: It also reads nice: eval mysql … Read more

Pass a PHP string to a JavaScript variable (and escape newlines) [duplicate]

Expanding on someone else’s answer: <script> var myvar = <?php echo json_encode($myVarValue); ?>; </script> Using json_encode() requires: PHP 5.2.0 or greater $myVarValue encoded as UTF-8 (or US-ASCII, of course) Since UTF-8 supports full Unicode, it should be safe to convert on the fly. Note that because json_encode escapes forward slashes, even a string that contains … Read more

Escape a string for a sed replace pattern

Warning: This does not consider newlines. For a more in-depth answer, see this SO-question instead. (Thanks, Ed Morton & Niklas Peter) Note that escaping everything is a bad idea. Sed needs many characters to be escaped to get their special meaning. For example, if you escape a digit in the replacement string, it will turn … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)