Display Text(HTML) Saved In Database using CkEditor - php

I have used CKEDITOR for saving some text in mysql database, it is saved in format like I have shown below
<p style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<span style="font-size: 14px;"><span style="font-family: arial, helvetica, sans-serif;">Buy 2 Buffet and Get 1 Free (Mon-Wed-Thu-Fri-Sat-Sun)</span></span><br />
<span style="font-size: 14px;"><span style="font-family: arial, helvetica, sans-serif;">Lunch buffet-</span></span><span style="font-size: 14px;"><span style="font-family: arial, helvetica, sans-serif;"><strong>Rs.399</strong><br />
Dinner Buffet-</span></span><strong><span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">Rs.499</span></strong></p>
<p style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
For Displaying it I have used php code like
echo htmlspecialchars_decode(stripslashes($main_row['meta_value']))
But it is showing output like
<p style="margin: 0px; padding: 0px; border: 0px; color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal;
line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">
<span style="font-size: 14px;"><span style="font-family: arial, helvetica, sans-serif;">Buy 2 Buffet and Get 1 Free (Mon-Wed-Thu-Fri-Sat-Sun)</span></span><br /> <span style="font-size: 14px;"><span style="font-family: arial, helvetica, sans-serif;">Lunch buffet-</span></span><span style="font-size: 14px;"><span style="font-family: arial, helvetica, sans-serif;"><strong>Rs.399</strong><br /> Dinner Buffet-</span></span>
I want to display this data as text, please help me out.

Just try to use
echo htmlspecialchars_decode($text);
And it will work .

try this:
echo htmlspecialchars_decode($main_row['meta_value'])
and let me know what is the result..

Use html_entity_decode it should work!
For example, assuming your text is stored in a variable called $text $text = html_entity_decode($text);

Related

Attachment sent with PHPMailer displayed behind HTML content

I'm sending mails with phpmailer 6.0.7. The received mail is presented like this:
Presentation in iOS Mail-App
I expected to have the attachment at the bottom of the mail content. Is there something I have to consider in my code. My code looks like this:
$mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->setFrom($user->get_mail(), utf8_decode($user->get_vorname()." ".$user->get_nachname()));
$mail->AddAddress($sr->get_mail(), utf8_decode($sr->get_vorname()." ".$sr->get_name()));
$mail->addReplyTo($user->get_mail(), $user->get_vorname()." ".$user->get_nachname());
$mail->IsHTML(true);
$mail->Subject = $betreff;
$mail->Body = getMailHTML(str_replace("\n", "<br/>", $mailBody), $foot);
$mail->addAttachment($file);
$mail->send();
EDIT
Here my HTML-Body:
function getMailHTML($body, $foot){
$output = "<!DOCTYPE html>
<html>
<head>
<meta charset=\"UTF-8\">
<title>SR-Ausschuss Online</title>
<style>
#font-face { font-family: \"Source Sans Pro\"; font-style: normal; font-weight: 400; src: local(\"Source Sans Pro Regular\"), local(\"SourceSansPro-Regular\"), url(\"https://fonts.gstatic.com/s/sourcesanspro/v11/6xK3dSBYKcSV-LCoeQqfX1RYOo3qOK7l.woff2\") format(\"woff2\"); unicode-range: U+0-FF, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
#font-face { font-family: \"Source Sans Pro Light\"; font-style: normal; font-weight: 300; src: local(\"Source Sans Pro Light\"), local(\"SourceSansPro-Light\"), url(\"https://fonts.gstatic.com/s/sourcesanspro/v11/6xKydSBYKcSV-LCoeQqfX1RYOo3ik4zwlxdu.woff2\") format(\"woff2\"); unicode-range: U+0-FF, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
#font-face { font-family: \"Source Sans Pro Bold\"; font-style: normal; font-weight: 700; src: local(\"Source Sans Pro Bold\"), local(\"SourceSansPro-Bold\"), url(\"https://fonts.gstatic.com/s/sourcesanspro/v11/6xKydSBYKcSV-LCoeQqfX1RYOo3ig4vwlxdu.woff2\") format(\"woff2\"); unicode-range: U+0-FF, U+131, U+152-153, U+2BB-2BC, U+2C6, U+2DA, U+2DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
.head{
position: absolute;
left: 0px;
top: 60px;
height: 50px;
width: 100%;
font-size: 35px;
}
.heading{
position: absolute;
left: 10px;
top: 0px;
line-height: 50px;
font-size: 35px;
color: #333;
font-family: 'Source Sans Pro Light';
}
.heading b{
font-family: 'Source Sans Pro Bold';
}
.container{
float: left;
position: absolute;
top: 120px;
left: 0px;
margin: 10px;
background-color: #fff;
padding: 20px;
width: -webkit-calc(100% - 60px);
width: -moz-calc(100% - 60px);
width: calc(100% - 60px);
}
.body{
width: -webkit-calc(100% - 30px);
width: -moz-calc(100% - 30px);
width: calc(100% - 30px);
font-family: 'Source Sans Pro','Helvetica Neue',Helvetica,Arial,sans-serif;
font-weight: 400;
font-size: 14px;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
float: both;
min-height: 20px;
}
a.button{
float: both;
display: block;
text-decoration: none;
width: -webkit-calc(100% - 30px);
width: -moz-calc(100% - 30px);
width: calc(100% - 30px);
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
background-color: #00a65a;
color: #fff;
text-align: center;
height: 40px;
line-height: 40px;
font-weight: 600;
}
.foot{
font-weight: 400;
font-size: 14px;
margin-left: 10px;
margin: 10px;
float: both;
min-height: 20px;
width: -webkit-calc(100% - 30px);
width: -moz-calc(100% - 30px);
width: calc(100% - 30px);
}
body{
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: 'Source Sans Pro','Helvetica Neue', Helvetica, Arial, sans-serif;
background-color: #d2d6de;
}
</style>
</head>
<body>
<div class=\"head\">
<span class=\"heading\"><b>SR-Ausschuss</b>Online</span>
</div>
<div class=\"container\">
<div class=\"body\">".$body."</div>
<div class=\"foot\">".$foot."</div>
</div>
</body></html>";
return $output;
}
Body and foot are simple text variables without any own html tags or something. There are only a few line breaks in it. Is it possble to give the attachment a fixed position in mail body?

How to stack results froma query in an Object-Oriented fashion

These are some of the inline-styles.
body{
font-family: helvetica;
font-size: 12px;
font-weight: normal;
color: gold;
margin: 0;
padding:0;
background: black;
}
p{
font-family: helvetica;
font-size: 12px;
font-weight: normal;
color: white;
margin: 0;
padding-top: 5px;
line-height: 14px;
}
header{
width: 100%;
height: 300px;
background-color: red;
border-bottom: 2px solid gold;
}
/* I would like to add a height to this wrapper, but when I do, the while loop doesn't stack the products in a row of 3. It just lists the products straight down the page. */
#wrapper{
width:618px;
margin: 10px auto;
/*background: yellow;*/
}
#stack{
width:201px;
height:200px;
float: left;
margin-right:5px;
margin-bottom:0px;
padding:0;
text-align:center;
/* background:pink;*/
}
a{
cursor:pointer;
color: gold;
text-decoration: none;
}
h3{
width:618px;
height:30px;
font-family: helvetica;
font-size: 16px;
font-weight: bold;
color:21a4ff;
margin: 0 auto;
text-align:center;
padding-top:10px;
}
p.price{
font-weight: bold;
color: tomato;
font-size: 14px;
line-height:10px;
}
p.name{
font-family: helvetica;
font-size: 13px;
font-weight: bold;
color: gold;
margin:0;
padding:0;
line-height: 12px;
}
</style>
<?php
include("mysql.connect.php");
$stmt = $mysqli->prepare("SELECT sku, name, price, sm_image
FROM products ORDER BY price");
$stmt->execute();
$stmt->bind_result($sku, $name, $price, $sm_image);
This is where my problem is. How can I set this while loop to list results in rows of three using the $stmt-fetch()) method?
while($stmt->fetch()){
echo "<div id='wrapper'>
<div id='stack'>
<img src='$sm_image'></img><br>
<p>$sku</p>
<p class='name'>$name</p>
<p class='price'>$$price<br></p>
</div>";
echo "</div>";
}
// Recuperate the statement resources
$stmt->close();
// Close the connection
$mysqli->close();
?>

php - how to return html inside json [duplicate]

This question already has answers here:
How to escape double quotes in JSON
(8 answers)
Closed 6 years ago.
I have some html inside my json array .this is an example :
{
"contacts": [
{ "id" : "1215" ,"price2":"0","tozih":"<span class="im_message_author_wrap" style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; text-align: start;"><br><span class="copyonly" style="color: transparent; display: inline-block; vertical-align: baseline; width: 1px; height: 0px; background: none 0px center no-repeat; font-size: 0px; float: left; text-rendering: auto; user-select: none;">:</span></span><span style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;"></span><span style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;"></span><span style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;"></span><span style="white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;">عكس تزيين شده زنجيرهاي استيل</span> تست <br>"} ]
the problem is , the double quote " is making json invalid ,is there any way to convert or encode ?
could you help me with this ?
Try given script
{
"contacts": [
{ "id" : "1215" ,"price2":"0","tozih":'<span class="im_message_author_wrap" style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; text-align: start;"><br><span class="copyonly" style="color: transparent; display: inline-block; vertical-align: baseline; width: 1px; height: 0px; background: none 0px center no-repeat; font-size: 0px; float: left; text-rendering: auto; user-select: none;">:</span></span><span style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;"></span><span style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;"></span><span style="color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;"></span><span style="white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Tahoma, sans-serif, Arial, Helvetica; font-size: 13px; text-align: start;">عكس تزيين شده زنجيرهاي استيل</span> تست <br>'}
]
}

PHP: str_replace doesn't work (Other answers on SO did not help)

I wrote the following SSCCE to demonstrate that I have a string (of some HTML), and I am using simple_html_dom parser to find out the div with a particular value of the class attribute. This works fine. But I need to remove this div from the parent string. So I am using str_replace, but it doesn't seem to work. Please tell me why and what is the solution.
I checked the solutions to questions addressing similar problems but they did not apply or work on my problem. I also tried to use str_replace_first from this question's answer by Bas. But it does not work either.
You can see in the screenshot that it just prints the entire $haystack after printing --------.
$haystack = '<div class="region-content" style="margin-right:100px; margin-left:100px;">
<div role="main"><span id="maincontent"></span><div class="que description informationitem notyetanswered" id="q6"><h4 class="accesshide">Question text</h4><input type="hidden" name="q3:6_:sequencecheck" value="1" /><div class="qtext"><p style="font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; margin: 0px 0px 20px; padding: 0px; color: #464646; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;">Schools expect textbooks to be a valuable source of information for students. My research suggests, however, that textbooks that address the place of Native Americans within the history of the United States distort history to suit a particular cultural value system. In some textbooks, for example, settlers are pictured as more humane, complex, skillful, and wise than Native Americans. In essence, textbooks stereotype and depreciate the numerous Native American cultures while reinforcing the attitude that the European conquest of the New World denotes the superiority of European cultures. Although textbooks evaluate Native American architecture, political systems, and homemaking, I contend that they do it from an ethnocentric, European perspective without recognizing that other perspectives are possible. </p>
<p style="font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; margin: 0px 0px 20px; padding: 0px; color: #464646; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;">One argument against my contention asserts that, by nature, textbooks are culturally biased and that I am simply underestimating children\'s ability to see through these biases. Some researchers even claim that by the time students are in high school, they know they cannot take textbooks literally. Yet substantial evidence exists to the contrary. Two researchers, for example, have conducted studies that suggest that children\'s attitudes about particular cultures are strongly influenced by the textbooks used in schools. Given this, an ongoing, careful review of how school textbooks depict Native Americans is certainly warranted.</p></div><div class="im-controls"><input type="hidden" name="q3:6_-seen" value="1" /></div></div>
<div class="que multichoice deferredfeedback notyetanswered" id="q7"><div class="qtext"><p><span style="color: #464646; font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">Which of the following would most logically be the topic of the paragraph immediately following the passage?</span></p></div><div class="ablock"><div class="prompt">Select one:</div><div class="answer"><div class="r0"><input type="radio" name="q3:7_answer" value="0" id="q3:7_answer0" /><label for="q3:7_answer0">a. <span style="color: #464646; font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">the contributions of European immigrants to the development of the United States</span></label> </div>
<div class="r1"><input type="radio" name="q3:7_answer" value="1" id="q3:7_answer1" /><label for="q3:7_answer1">b. <span style="color: #464646; font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;"><span class="Apple-converted-space"> </span>the centrality of the teacher\'s role in United States history courses</span></label> </div>
<div class="r0"><input type="radio" name="q3:7_answer" value="2" id="q3:7_answer2" /><label for="q3:7_answer2">c. <span style="color: #464646; font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">nontraditional methods of teaching United States history</span></label> </div>
<div class="r1"><input type="radio" name="q3:7_answer" value="3" id="q3:7_answer3" /><label for="q3:7_answer3">d. <span style="color: #464646; font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">specific ways to evaluate the biases of United States history textbooks <br /></span></label> </div>
<div class="r0"><input type="radio" name="q3:7_answer" value="4" id="q3:7_answer4" /><label for="q3:7_answer4">e. <span style="color: #464646; font-family: HelveticaNeueW01-55Roma, Helvetica, Arial, san-serif; font-size: 14.4444446563721px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 19.5px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: #ffffff;">ways in which parents influence children\'s political attitudes <br /></span></label> </div>
</div></div></div>';
require('C:/xampp/htdocs/simple_html_dom.php');
$html = str_get_html($haystack);
foreach($html->find('div[class=que description informationitem notyetanswered]') as $h) {
$reading_passage_outertext = $h->outertext;
}
$hay = str_replace($reading_passage_outertext, "", $haystack);
echo $reading_passage_outertext;
echo '---------------------------------------------------------------------------------------------------------------';
echo $hay;
I guess outertext is returning an interpretation of parsed html. So it probably removes excess spaces, and may jumble the order of attributes. In other words you're getting a different string out than what str_get_html took in. You may want to just remove the div using the parser instead of str_replace
What I can see on your example is, that
$hay = str_replace($reading_passage_outertext, "", $haystack);
echo $reading_passage_outertext;
is outside of the foreach.
So $reading_passage_outertext only contains the last entry and str_replace does not really work.
I'm also not realy shure why you run through the str_get_html.
It doesn't make sense and costs quite some performance.
str_replace also accepts arrays as pattern and replacement values.
Try using str_replace only.

Warning: Cannot modify header information - headers already sent by (output) [duplicate]

This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I'm getting this error again and again i try everything but i can't found solution
Warning: Cannot modify header information - headers already sent by (output started at /home/xxxx/xxxx/forum/index.php:90) in /home/pappu/public_html/forum/index.php on line 93
here is my index.php code
<?php
include_once("connect.php");
session_start();
?>
<html>
<head>
<title>MyForum</title>
<style type="text/css">
body {
background-color: #333;
margin-top: 150px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
.content {
background-color: #666;
width: 960px;
margin-right: auto;
margin-left: auto;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
padding: 20px;
}
.content .categories {
width: 700px;
background-color: #333;
border-radius: 3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
margin: 0px;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
color: #FFF;
}
.categories .community_heading {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-variant: normal;
text-transform: capitalize;
color: #CCC;
margin: 0px;
padding-top: 7px;
padding-right: 7px;
padding-bottom: 7px;
padding-left: 14px;
font-size: 18px;
font-weight: bold;
}
.content .categories hr {
background-color: #666;
height: 3px;
border: 0px;
width: 700px;
margin: 0px;
}
.content .categories .cat_links {
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: #000;
padding-top: 7px;
padding-right: 7px;
padding-bottom: 7px;
padding-left: 14px;
font-size: 14px;
color: #000;
}
.content .categories .cat_a {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 18px;
font-variant: normal;
text-transform: capitalize;
color: #777;
text-decoration: none;
}
.content .categories .cat_a:hover {
text-decoration: underline;
color: #DDD;
}
.content .categories .desc {
margin: 0px;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #CCC;
}
</style>
</head>
<body>
<?php
if(!isset($_SESSION['password']))
{
include_once("Location:header.php");
}
else
{
header("Location:member.php");
}
?>
<div class="content">
<div class="categories">
<h3 class="community_heading">Community</h3>
<hr />
<?php
$query = "SELECT * FROM categories ORDER BY cat_id ASC";
$result = mysql_query($query) or die(mysql_error());
$categories = "";
if(mysql_num_rows($result) > 0 )
{
while($row = mysql_fetch_array($result))
{
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
$cat_desc = $row['cat_description'];
$categories .="
<div class='cat_links'>
<a href='view_category?cid=".$cat_id."' class='cat_a'>$cat_title</a>
<p class='desc'>$cat_desc</p>
</div>";
}
echo $categories ;
}
else
{
}
?>
</div>
</div>
</body>
</html>
You can't call Header() after including ANY code that is outputted to the page. You need to rewrite what you are doing so the Header() call is above all the HTML code.

Categories