Questions tagged [htmlspecialchars]

htmlspecialchars is a PHP function that convert special characters to HTML entities.

htmlspecialchars is a PHP function that convert special characters to HTML entities.

Famous question: htmlentities() vs. htmlspecialchars()

467 questions
80
votes
3 answers

is there a way to highlight all the special accent characters in sublime text or any other text editor?

I a using the the HTML encode special characters in Sublime text to convert all the special character into their HTML code. I have a lot of accented characters in different parts of the file. So, it would be great if I could select all the special…
kashive
  • 1,356
  • 2
  • 11
  • 17
60
votes
1 answer

What do the ENT_HTML5, ENT_HTML401, ... modifiers on html_entity_decode do?

Since php 5.4 html_entity_decode introduces four new flags, with a minimal explanation ENT_HTML401 Handle code as HTML 4.01. ENT_XML1 Handle code as XML 1. ENT_XHTML Handle code as XHTML. ENT_HTML5 Handle code as HTML 5. I want to…
Saic Siquot
  • 6,513
  • 5
  • 34
  • 56
45
votes
3 answers

How to replace decoded Non-breakable space (nbsp)

Assuming I have a sting which is "a s d d" and htmlentities turns it into "a s d d". How to replace (using preg_replace) it without encoding it to entities? I tried preg_replace('/[\xa0]/', '', $string);, but it's not working. I'm…
Grzegorz
  • 3,538
  • 4
  • 29
  • 47
40
votes
4 answers

reverse htmlspecialchars

this may seem like a simple problem but I couldn't find it in the archives. how does one reverse the effects of htmlspecialchars? I tried something like this: $trans_tbl = get_html_translation_table (HTML_ENTITIES); $trans_tbl = array_flip…
Ray S.
  • 1,192
  • 3
  • 15
  • 27
30
votes
4 answers

when to use htmlspecialchars() function?

Hi I was wondering when is the appropriate place to use htmlspecialchars(). Is it before inserting data to database or when retrieving them from the database?
khr2003
  • 1,055
  • 4
  • 12
  • 21
28
votes
1 answer

Which are the HTML, and XML, special characters?

What are the special reserved character entities in HTML and in XML? The information that I have says: HTML: & (replace with &) < (replace with <) > (replace with >) " (replace with ") ' (replace with ') XML: < (replace with…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
20
votes
8 answers

Is there a Python equivalent to the PHP function htmlspecialchars()?

Is there a similar or equivalent function in Python to the PHP function htmlspecialchars()? The closest thing I've found so far is htmlentitydefs.entitydefs().
Ian
  • 24,116
  • 22
  • 58
  • 96
20
votes
3 answers

json with special characters like é

I'm developing a dependent select script using jQuery, PHP and JSON as the response. Everything goes well except for using special characters like French ones (é , è , à...) if I pre-encode them like (é , è , à) (Here I'm using…
medk
  • 9,233
  • 18
  • 57
  • 79
20
votes
10 answers

How to display special characters in PHP

I've seen this asked several times, but not with a good resolution. I have the following string: $string = "

Résumé

"; I want to print or echo the string, but the output will return

R�sum�

. So I try htmlspecialchars() or htmlentities()…
Phil Tune
  • 3,154
  • 3
  • 24
  • 46
18
votes
1 answer

filter_var vs htmlentities vs htmlspecialchars

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…
Charles Sprayberry
  • 7,741
  • 3
  • 41
  • 50
17
votes
6 answers

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

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…
Garry
  • 251
  • 2
  • 13
16
votes
6 answers

htmlspecialchars(): Invalid multibyte sequence in argument

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.
gautamlakum
  • 11,815
  • 23
  • 67
  • 90
14
votes
2 answers

htmlspecialchars utf-8 returns empty string

I'm doing a .php RSS generator and I have a problem trying to get data from my database in this line: ...]]> Some entries show just…
Santiago
  • 2,405
  • 6
  • 31
  • 43
13
votes
1 answer

Is it good to use htmlspecialchars() before Inserting into MySQL?

I am a little confused on this. I have been reading about htmlspecialchars() and I am planning to use this for the textareas POST to prevent XSS attack. I understand that usually htmlspecialchars() are used to generate the HTML output that is sent…
Neel
  • 9,352
  • 23
  • 87
  • 128
12
votes
1 answer

Notice: Use of undefined constant ENT_HTML5 - assumed 'ENT_HTML5'

I am trying to create a simple method which accepts the parameters for htmlspecialchars. Although I am getting PHP notice: Use of undefined constant ENT_HTML5 - assumed 'ENT_HTML5' Any ideas what could be causing this? /** * Encode string. * …
John Magnolia
  • 16,769
  • 36
  • 159
  • 270
1
2 3
31 32