html-entities

Why does the PHP function htmlentities(…) returns wrong results?

妖精的绣舞 提交于 2019-12-05 14:58:42
I have the following code : function testAccents() { $str = "àéè"; $html = htmlentities($str); echo $html; } When I run it, instead of getting àéè I get àéè . I thought that it could be a problem of encoding but the file is utf-8 : > file -bi PublicationTest.php text/x-c++; charset=utf-8 Why do I get this strange result ? EDIT: I use PHP 5.3. Before PHP 5.4.0, htmlentities() expects ISO-8859-1 data by default. It's interpreting your UTF-8 input as single-byte characters, which results in the funny results you get. Specify the encoding specifically. $html = htmlentities($str, ENT_COMPAT,

htmlentities equivalent in JSP?

吃可爱长大的小学妹 提交于 2019-12-05 14:05:56
I'm a php guy, but I have to do some small project in JSP. I'm wondering if there's an equivalent to htmlentities function (of php) in JSP. public static String stringToHTMLString(String string) { StringBuffer sb = new StringBuffer(string.length()); // true if last char was blank boolean lastWasBlankChar = false; int len = string.length(); char c; for (int i = 0; i < len; i++) { c = string.charAt(i); if (c == ' ') { // blank gets extra work, // this solves the problem you get if you replace all // blanks with  , if you do that you loss // word breaking if (lastWasBlankChar) { lastWasBlankChar

Characters not displaying correctly on a UTF-8 website

一曲冷凌霜 提交于 2019-12-05 11:34:17
I've done everything I can think of, but special characters are not displaying correctly on this webpage. For example, in the database it's: But on the site it's: Nouveaux R�alistes Here's everything I've checked... The database is set to UTF-8: The page was written in NetBeans, with the document encoding set to UTF-8: The page header declares UTF-8: The meta charset is set to UTF-8: I've even added the following line to my .htacess: But there characters are still not displaying correctly, and I get the following error from the W3C Validator: I feel like I've attempted everything, but it still

How to get char from HTML character code?

别等时光非礼了梦想. 提交于 2019-12-05 10:39:47
How can I convert the HTML entities € ► ♠ to their actual characters € ► ♠ using JavaScript? An example would be: alert(String.fromCharCode(8364)); Where 8364 is the number of the HTML entity. To replace a full body of text automatically then you will need to use this regular expression replacement example: "The price of milk is now €100000.".replace(/&#(\d{0,4});/g, function(fullStr, str) { return String.fromCharCode(str); }); The magic happens here: replace(/&#(\d{1,4});/g, function(fullStr, code) { return String.fromCharCode(code); }); The first argument to replace, /&#(\d{1,4});/g ,

XML Parsing Error: undefined entity - special characters

喜欢而已 提交于 2019-12-05 05:33:49
Why does XML display error on certain special characters and some are ok? For instance, below will create error, <?xml version="1.0" standalone="yes"?> <Customers> <Customer> <Name>Löic</Name> </Customer> </Customers> but this is ok, <?xml version="1.0" standalone="yes"?> <Customers> <Customer> <Name>&</Name> </Customer> </Customers> I convert the special character through php - htmlentities('Löic',ENT_QUOTES) by the way. How can I get around this? Thanks. EDIT: I found that it works fine if I use numeric character such as Lóic now I have to find how to use php to convert special characters

PHP htmlspecialchars is not working [closed]

筅森魡賤 提交于 2019-12-05 03:22:19
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center . Closed 8 years ago . <?php $new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES); echo $new; ?> output should be & lt;a href=& #039;test& #039;>Test& lt;/a& gt; but output is <a href='test'>Test</a> Don't worry. htmlspecialchars() is encoding the < and > characters properly. It is just that when you echo the encoded string

how to encode single quotes

不羁岁月 提交于 2019-12-04 14:37:06
I want to know how i use htmlentities •' for ' in my code ? How to escape single quote hows apostrophe work in IE while($row = pg_fetch_array($result)) { if($row[3]=="") { $vmobj_Array[$i]=$row[0]."***".$row[1]."***".$row[2]; } else { $vmobj_Array[$i]=$row[0].' ( '.$row[3].' )'."***".$row[1]."***".$row[2]; } $i++; } I think every question should have an answer, so I'm posting here as well. Feel free to accept the answer someone else posted there just now. htmlentities($str, ENT_QUOTES); or htmlspecialchars($str, ENT_QUOTES); should do the trick where $str should be replaced by the variable or

ASCII to HTML-Entities Escaping in Java

梦想的初衷 提交于 2019-12-04 14:21:34
I found this website with escape codes and I'm just wondering if someone has done this already so I don't have to spend couple of hours building this logic: StringBuffer sb = new StringBuffer(); int n = s.length(); for (int i = 0; i < n; i++) { char c = s.charAt(i); switch (c) { case '\u25CF': sb.append("●"); break; case '\u25BA': sb.append("►"); break; /* ... the rest of the hex chars literals to HTML entities */ default: sb.append(c); break; } } These "codes" is a mere decimal representation of the unicode value of the actual character. It seems to me that something like this would work,

array_map and htmlentities

核能气质少年 提交于 2019-12-04 12:41:39
I've been trying using array_map to convert characters to HTML entities with htmlentities() like this: $lang = array_map('htmlentities', $lang); My array looks like this: $lang = array(); $lang['var_char1']['varchar2'] = 'Some Text'; But I keep getting this errors : Warning: htmlentities() expects parameter 1 to be string, array given in /home/user/public_html/foo/lang/en.inc.php on line 1335 Does anyone know what could be the problem? Thank you! Because $lang is a two dimensional array, so it won't work For two dimensional array you need to use for loop foreach($$lang as &$l): $l = array_map(

Ruby gem install and “No such file to load”

耗尽温柔 提交于 2019-12-04 12:41:12
问题 I'm scripting with Ruby 1.9.2dev in Backtrack 5 but I'm having some problems when try to parse html entities with the library "htmlentities". I cannot load the library although I have installed it with gem. I'll show you the problems I'm having in the console: root@bt:~# gem list -d htmlentities *** LOCAL GEMS *** htmlentities (4.3.1) Author: Paul Battley Homepage: https://github.com/threedaymonk/htmlentities Installed at: /var/lib/gems/1.9.2 A module for encoding and decoding (X)HTML