htmlspecialchars

how to convert new line and html code in htmlspecialchars in php

a 夏天 提交于 2019-12-01 14:53:02
here is my string hello world <textarea>hello world</textarea> how can I convert this string hello &nbsp; world &nbsp; &nbsp; &lt;textarea&gt;hello world&lt;/textarea&gt; in php. Any one help please... I am try htmlspecialchars(); function but that doesn't work perfect. please read more on php ..Maybe this can help you https://www.w3schools.com/pHp/default.asp <?php echo "hello"; echo "</br>"; echo "world"; echo "</br>"; echo "</br>"; echo "<input type = 'textare' value = 'hello world'>"; ?> 来源: https://stackoverflow.com/questions/45114200/how-to-convert-new-line-and-html-code-in-htmlspecialchars-in-php

Using HTML Purifier on a site with only plain text input

巧了我就是萌 提交于 2019-12-01 14:16:57
I would appreciate an answer to settle a disagreement between me and some co-workers. We have a typical PHP / LAMP web application. The only input we want from users is plain text. We do not invite or want users to enter HTML at any point. Form elements are mostly basic input text tags. There might be a few textareas, checkboxes etc. There is currently no sanitizing of output to pages. All dynamic content, some of which came from user input, is simply echoed to the page. We obviously need to make it safe. My solution is to use htmlspecialchars on all output at the time it is echoed on the page

replace all but certain html tags with htmlspecialchars() in PHP?

末鹿安然 提交于 2019-12-01 11:50:44
问题 I would like to process my user input to allow only certain html tags, and replace the other ones by their html entities, as well as replace non-tag-characters. For example, if I only wanted to allow the <b> and the <a> tag, then allow_only("This is <b>bold</b> and this is <i>italic</i>. Moreover 2<3 and <a href='google.com'>this is a link</a>.","<b><a>"); should produce This is <b>bold</b> and this is <i>italic</i>. Moreover 2<3 and <a href='google.com'>this is a link</a>. How can I do this

Sanitizing PHP/SQL $_POST, $_GET, etc…?

假装没事ソ 提交于 2019-12-01 11:31:47
Ok, this subject is a hotbed I understand that. I also understand that this situation is dependent on what you are using as code. I have three situations that need to be resolved. I have a form in where we need to allow people to make comments and statements that use commas, tildes, etc... but still remain safe from attacks. I have people entering in dates like this: 10/13/11 mm/dd/yy in English, can this be sanitized? How do I understand how to use htmlspecialchars() , htmlentities() and real_escape_string() correctly? I've read the php.net site and some posts here but this seems to me to be

Do you only run htmlspecialchars() on output or is there other functionality you also do?

六眼飞鱼酱① 提交于 2019-12-01 04:34:09
问题 When outputting user input, do you only use htmlspecialchars() or are there are functions/actions/methods you also run? I'm looking for something that will also deal with XSS. I'm wondering if I should write a function that escapes user input on output or just use htmlspecialchars() . I'm looking for the generic cases, not the specific cases that can be dealt with individually. 回答1: I usually use htmlspecialchars($var, ENT_QUOTES) on input fields. I created a method that does this because i

How Do I use htmlspecialchars but allow only specific HTML code to pass through without getting converted?

无人久伴 提交于 2019-12-01 02:42:10
Here is the line of code I have which works great: $content = htmlspecialchars($_POST['content'], ENT_QUOTES); But what I would like to do is allow only certain types of HTML code to pass through without getting converted. Here is the list of HTML code that I would like to have pass: <pre> </pre> <b> </b> <em> </em> <u> </u> <ul> </ul> <li> </li> <ol> </ol> And as I go, I would like to also be able to add in more HTML later as I think of it. Could someone help me modify the code above so that the specified list of HTML codes above can pass through without getting converted? I suppose you could

filter_var vs htmlentities vs htmlspecialchars

喜夏-厌秋 提交于 2019-12-01 02:41:23
Disclaimer This is not a question about whether we should be escaping for database input. This is strictly looking at the technical differences between the three functions in the title. There is this question discussing the difference between htmlentities() and htmlspecialchars() . But, it doesn't really discuss filter_var() and the information I found on Google was more along the lines of "Make sure you escape user input before it is echo'd!" My questions are: Why are htmlspecialchars() and htmlentities() commonly used over filter_var() ? Is there some performance hit from using filter_var()

filter_var vs htmlentities vs htmlspecialchars

ぃ、小莉子 提交于 2019-11-30 22:15:01
问题 Disclaimer This is not a question about whether we should be escaping for database input. This is strictly looking at the technical differences between the three functions in the title. There is this question discussing the difference between htmlentities() and htmlspecialchars(). But, it doesn't really discuss filter_var() and the information I found on Google was more along the lines of "Make sure you escape user input before it is echo'd!" My questions are: Why are htmlspecialchars() and

C++ tolower on special characters such as ü

与世无争的帅哥 提交于 2019-11-29 15:07:41
I have trouble transforming a string to lowercase with the tolower() function in C++. With normal strings, it works as expected, however special characters are not converted successfully. How I use my function: string NotLowerCase = "Grüßen"; string LowerCase = ""; for (unsigned int i = 0; i < NotLowerCase.length(); i++) { LowerCase += tolower(NotLowerCase[i]); } For example: Test -> test TeST2 -> test2 Grüßen -> gr????en (§) -> () 3 and 4 are not working as expected as you can see How can I fix this issue? I have to keep the special chars, but as lowercase. The sample code (below) from

htmlspecialchars(): Invalid multibyte sequence in argument

谁说我不能喝 提交于 2019-11-29 01:29:07
I am getting this error in my local site. Warning (2): htmlspecialchars(): Invalid multibyte sequence in argument in [/var/www/html/cake/basics.php, line 207] Does anyone knows, what is the problem or what should be the solution for this? Thanks. Tatu Ulmanen Be sure to specify the encoding to UTF-8 if your files are encoded as such: htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); The default charset for htmlspecialchars is ISO-8859-1 (as of PHP v5.4 the default charset was turned to 'UTF-8'), which might explain why things go haywire when it meets multibyte characters. I ran in to this error on