html-entities

Why does <textarea> display <> instead of <>?

两盒软妹~` 提交于 2020-01-24 12:49:08
问题 Shouldn't a browser's textarea display raw text? Look at the following snaps from this post, and pay attention to the <script> tag: 1- We can see the angled brackets around the script word: 2- Now look at the source of the page. We can see the angled brackets are represented by their HTML entities: 3- Click to edit the post and you'll see that the angled brackets are visible in the textarea--NOT their HTML entities: 4- Look at the XHR response from the server (when we clicked edit), we can

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

折月煮酒 提交于 2020-01-22 05:48:04
问题 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(). 回答1: Closest thing I know about is cgi.escape. 回答2: from django.utils.html import escape print escape('<div class="q">Q & A</div>') 回答3: You probably want xml.sax.saxutils.escape: from xml.sax.saxutils import escape escape(unsafe, {'"':'"'}) # ENT_COMPAT escape(unsafe, {'"':'"', '\'':'''}) # ENT_QUOTES escape(unsafe) # ENT_NOQUOTES

html_entity_decode problem in PHP?

倾然丶 夕夏残阳落幕 提交于 2020-01-20 18:36:25
问题 I am trying to convert HTML entities from a source string to their literal character equivalent. For example: <?php $string = "Hello – World"; $converted = html_entity_decode($string); ?> Whilst this rightly converts the entity on screen, when I look at the HTML code it is still showing the explicit entity. I need to change that so that it literally converts the entity as I am not using the string within an HTML page. Any ideas on what I am doing wrong? FYI I am sending the converted string

Special characters and double quotes issue in PHP

一个人想着一个人 提交于 2020-01-16 00:55:27
问题 I have this kind of value in my db column, Judge-Fürstová Mila "Ut enim ad minim veniam" I use PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" to handle all my special characters, class database_pdo { # database handler protected $connection = null; # make a connection public function __construct($dsn,$username,$password) { try { $this->connection = new PDO($dsn, $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $this->connection->setAttribute(PDO::ATTR_ERRMODE,

PHP htmlentities and saving the data in xml format

给你一囗甜甜゛ 提交于 2020-01-15 23:39:37
问题 Im trying to save some data into a xml file using the following PHP script: <?php $string = '<a href="google.com/maps">Go to google maps</a> and some special characters ë è & ä etc.'; $string = htmlentities($string, ENT_QUOTES, 'UTF-8'); $doc = new DOMDocument('1.0', 'UTF-8'); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $root = $doc->createElement('top'); $root = $doc->appendChild($root); $title = $doc->createElement('title'); $title = $root->appendChild($title); $id = $doc-

PHP htmlentities and saving the data in xml format

╄→гoц情女王★ 提交于 2020-01-15 23:37:32
问题 Im trying to save some data into a xml file using the following PHP script: <?php $string = '<a href="google.com/maps">Go to google maps</a> and some special characters ë è & ä etc.'; $string = htmlentities($string, ENT_QUOTES, 'UTF-8'); $doc = new DOMDocument('1.0', 'UTF-8'); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $root = $doc->createElement('top'); $root = $doc->appendChild($root); $title = $doc->createElement('title'); $title = $root->appendChild($title); $id = $doc-

How can I use PHP's preg_replace function to convert Unicode code points to actual characters/HTML entities?

我怕爱的太早我们不能终老 提交于 2020-01-13 19:15:10
问题 I want to convert a set of Unicode code points in string format to actual characters and/or HTML entities (either result is fine). For example, if I have the following string assignment: $str = '\u304a\u306f\u3088\u3046'; I want to use the preg_replace function to convert those Unicode code points to actual characters and/or HTML entities. As per other Stack Overflow posts I saw for similar issues, I first attempted the following: $str = '\u304a\u306f\u3088\u3046'; $str2 = preg_replace('/\u[0

Encoding issue, coverting & to & for html using php

痴心易碎 提交于 2020-01-12 13:59:44
问题 I have a url in html: <a href="index.php?q=event&id=56&date=128"> I need to turn it into a string exactly as: <a href="index.php?q=event&id=56&date=128"> I know how to do this with preg_replace etc, but is there a function in php that deals directly with encoding that I can use for other encoding issues such as &nsbp (or whatever it is, etc)? Ideally I would send my string into the function and it would output '&' instead of &amp. Is there a universal function for converting &TEXT; into an

Encoding issue, coverting & to & for html using php

断了今生、忘了曾经 提交于 2020-01-12 13:56:50
问题 I have a url in html: <a href="index.php?q=event&id=56&date=128"> I need to turn it into a string exactly as: <a href="index.php?q=event&id=56&date=128"> I know how to do this with preg_replace etc, but is there a function in php that deals directly with encoding that I can use for other encoding issues such as &nsbp (or whatever it is, etc)? Ideally I would send my string into the function and it would output '&' instead of &amp. Is there a universal function for converting &TEXT; into an

how to make Nokogiri not to convert   to space

…衆ロ難τιáo~ 提交于 2020-01-10 07:43:14
问题 i fetch one html fragment like "<li>市 场 价" which contains "   ", but after calling to_s of Nokogiri NodeSet, it becomes "<li>市 场 价" , i want to keep the original html fragment, and tried to set :save_with option for to_s method, but failed. can someone encounter the same problem and give me help? thank you in advance. 回答1: I encountered a similar situation, and what I came up was a bit of a hack, but it seems to work well. nbsp = Nokogiri::HTML(" ").text text.gsub(nbsp, " ") In my case, I