So i added TinyMCE with this method
<script src="https://cdn.tiny.cloud/1/myapihere/tinymce/5/tinymce.min.js"></script>
<script>tinymce.init({selector:'textarea'});</script>
and added a textarea later on the text. But for some reason
This is what i want it to show to me, when the post is updated
This is what it shows me
If I understand correctly, your problem is that when you output the string from tinyMCE, you get the raw html without any formatting.
I think the problem is how you output the string. When outputting HTML in a blade template, don't use {{ $content }}, this will automatically encode html entities.
To output HTML, you have to use {!! $content !!}. This will output your string as is and won't parse html entities.
Related
How to render html on my FPDF file? the content always showing strings with HTML tags for example if I input like this
the output will be like this
I tried strip_tags() like below to output the content without tags but the HTML shows no effect/rendering.
strip_tags($item['output'])
What can you suggest me to use?
You should use WriteHTML() method.
See http://www.fpdf.org/en/script/script42.php
Currently i am doing a CMS in laravel currently i am trying to get all the html removed from posts.
{!! str_limit($post->content, 230) !!}
The problem i am getting is that it gets html as well.
Next i tried Strip_tags function, it didn't display the html.
{!! strip_tags(str_limit($post->content, 230)) !!}
But it didn't displayed anything either..it worked but it counted the html tags as well. I need to just ignore html tags.
Is there any way or function to ignore all the html tags inside the post content and just get the text out of post content?
Thanks
Any help will be appreciated!
Simple use strip_tags with substr
<?php echo substr(strip_tags($post->content,0,110)) . "..."; ?>
I save html in my database and when I recover this html in my view I see it like text in my browser and not html tags.
Example :
I save "<div><h1>Hello</h1></div>"
But when I echo it, the browser prints the tags as raw data, and not as HTML markup.
I guess you echo it like {{$string}}
This works same as e() function (PHP: htmlentities)
in order to echo html in Laravel Blade echo it like this {!! $string !!} to pass over HTML clean
By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:
Hello, {!! $name !!}
I've found what I want ! Juste use htmlspecialchars_decode() and it works !
I'm receiving a chunk of HTML via API call and trying to put that HTML into my template for it to render. But, instead of rendering, it's being printed out as if it were a string.
Example of HTML string from API:
\u0026lt;p\u0026gt;\u0026lt;strong\u0026gt;Hello World\u0026lt;/strong\u0026gt;\u0026lt;/p\u0026gt;
Then in the controller I convert the string to HTML entities
$content = htmlspecialchars_decode($response['content']);
The issue I'm having is that in my view, the HTML is printed (tags and all) instead of being rendered as HTML:
In view code:
<?= $content ?>
End result:
<p><strong>Hello World</strong></p>
How can I get this HTML chunk to render in my view?
Your data looks like double-encoded. Try
$content = htmlspecialchars_decode(htmlspecialchars_decode($response['content']));
From the looks of your string, you don't need htmlspecialchars_decode(), since you don't have HTML special characters directly in it.
I suspect you are getting your data in JSON format. A JSON-encoded value can sometimes have special characters converted to Unicode constants (for example, the PHP json_encode() function does that when used with the JSON_HEX_* options).
Try this:
$content = json_decode('"' . $response['content'] . '"');
I have a $text variable that holds some text and HTML code. I would like to render its HTML, but still make sure the rest of the string is escaped.
$text = 'Example text with image <img src"image_1.jpg">. More text...'
// This will render the HTML but will NOT escape the string
{!! $text !!}
// This will escape and display the variable as raw string, with no HTML rendering
{{ $text }}
In Laravel 5, is there a way to escape a string with Blade while allowing HTML?
I am not aware of such functionality in blade. You can not just allow specific HTML tags, because they may have unwanted stuff (like onload) inside them. Processing of string may be tricky. Have you considered markup language?
In this case you need to do some manual processing of the string.
It might be possible that Purifier https://github.com/mewebstudio/Purifier will do what you need. It will make strings harmless and then it is safe to print the html in it.
Otherwise you need to write your own parser if nothing else like that is found.