How can I print html code that has been created by a WYSIWYG editor with PHP? When I print it with "echo", then it shows the html code on the website only, rather than interpreting it as html tags.
Thanks for your answer.
What you need is htmlspecialchars_decode
htmlspecialchars_decode — Convert special HTML entities back to characters
Related
Is there a way to display the ascii code ("é" for "é", and not display "é" but "é") in html using pre code? The only way I could find was to use a text/plain header header in PHP but then I would lose all possible styling. Why? because I have to work on a doc where people have to paste some ascii codes so I would need to be able to style and still display code and not render them.
The htmlspecialchars() function will convert characters with special meaning in HTML (like &) to their character references so that they will be displayed instead of having their special meaning.
I have a database table (SQL Server 2008) with a table that contains some ASCII-encoded characters (formatted as nvarchar(max) ).
Usually the browser converts these automatically to HTML but I use a jQuery plugin that cannot read these and requires the content in HTML. I am passing my content to this plugin using PHP.
Is there a way in PHP to convert such strings manually to HTML ?
Example - db content:
<p>Some sample text with <strong>HTML</strong></p>
Example - required output for plugin:
<p>Some sample text with <strong>HTML</strong></p>
I tried finding a solution myself but it seems there are different approaches available and I wasn't sure about the correct one here.
you can try html_entity_decode();
html_entity_decode('string', ENT_QUOTES, 'UTF-8');
use this,
echo html_entity_decode($string, ENT_COMPAT, 'UTF-8');
I'm working with PHP, getting html from websites, converting them to plain text and saving them to the database.
They need to be saved to the database in utf-8.
My first problem is that I don't know the original encoding, what's the best way to encode to utf-8 from an unknown encoding?
the 2nd issue is the html to plain text conversion. I tried using html2text but it messed up all the foreign utf characters.
What is the best approach?
Edit: It seems the part about plain text is not clear enough. What i need not to just strip the html tags. I want to strip the tags while maintaining a kind of document structure. <p>, <li> tags would convert to line breaks etc and tags like <script> would be completely removed with their content.
Use mb_detect_encoding() for encoding detection.
Use strip_tags() to get rid of HTML tags.
Rest of the subjects like formatting the output depends on your needs.
Edit: I don't know if a complete solution exists but this link is really helpful to improve existing html to text PHP scripts on your own.
http://www.phpwact.org/php/i18n/utf-8
This function may be useful to you:
<?php
function FixEncoding($x){
if(mb_detect_encoding($x)=='UTF-8'){
return $x;
}else{
return utf8_encode($x);
}
}
?>
I'm trying to read a source code for a webPage that contains Arabic text but all what am getting is this جامعة (which is not Arabic, only a group of characters).
If I reload the page on my localhost I get the Arabic tags and text correctly.
But I really need to read that source code. any suggestions or lines of code I can add?
<html dir=rtl>
<META http-equiv=Content-Type content=text/html;charset=windows-1256>
These are few lines from that include the "encoding" used! The page is written using HTML and PHP
The characters are merely escaped to HTML entities. The browser decodes them to "real characters" when it renders the page. You can decode them yourself using html_entity_decode:
html_entity_decode('جامعة', ENT_COMPAT, 'UTF-8')
Note the last parameter, which sets the encoding the characters will be decoded to. Use whatever encoding you're working with internally, I'm just suggesting UTF-8 here.
I'm having trouble finding the correct setting for HTML Purifier 4.3.0 to convert diacritics to numerical HTML code. Is this possible using this library?
So, from încă to încă .
As you can see in the demo: by default: no. To me, but there isn't a clear description of what it does and doesn't, HTML Purifier looks like it's meant to strip html tags from input.
I think you're better off using htmlentities().
If you're working in UTF-8 mode, as HTML Purifier does by default, there's no need to escape character entities. If you tell HTML Purifier that you're working in ASCII mode, it will do so for you.