html标签在哪里找,我的html标签在哪里?

作者探讨了如何在将HTML内容存入数据库后,仍能保持格式的问题,重点在于htmlspecialchars()处理后的HTML丢失。文章揭示了PHP代码实例,以及可能的解决方案,如使用BASE64编码或改进存储策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开始对这种形式感到沮丧。我将HTML内容提交给我的数据库,以便存储和检索以在我的前端显示。我已经确保使用htmlspecialchars(),但是,保存后,我的所有代码都被清除为纯文本。我的html标签在哪里?

我读过大量与我的问题几乎完全相同的帖子,但还没有找到合适的答案。

这里是我遇到的麻烦的代码:

Article Summary

<?php echo htmlspecialchars($results['article']->summary)?>

CKEDITOR.replace('summary', {

filebrowserBrowseUrl: 'wysiwyg/kcfinder/browse.php? opener=ckeditor&type=files',

filebrowserImageBrowseUrl: 'wysiwyg/kcfinder/browse.php? opener=ckeditor&type=images',

filebrowserFlashBrowseUrl: 'wysiwyg/kcfinder/browse.php? opener=ckeditor&type=flash',

filebrowserUploadUrl: 'wysiwyg/kcfinder/upload.php? opener=ckeditor&type=files',

filebrowserImageUploadUrl: 'wysiwyg/kcfinder/upload.php? opener=ckeditor&type=images',

filebrowserFlashUploadUrl: 'wysiwyg/kcfinder/upload.php? opener=ckeditor&type=flash'

});

这是我输入的例子:

这里的输出:

pimg alt"" src"wysiwygkcfinderuploadimagesplymouth.png" style"height:323px width:549px" p

其提交给我数据库,它被检索并显示在我的前端,只是没有html。此外,该输出是它被存储在数据库中的方式。

这里发生了什么?

编辑:请求的PHP代码。

/**

* Class to handle articles

*/

class Article

{

// Properties

/**

* @var int The article ID from the database

*/

public $id = null;

/**

* @var int When the article is to be/was first published

*/

public $publicationDate = null;

/**

* @var string Full title of the article

*/

public $title = null;

/**

* @var string A short summary of the article

*/

public $summary = null;

/**

* @var string The HTML content of the article

*/

public $content = null;

/**

* Sets the object's properties using the values in the supplied array

*

* @param assoc The property values

*/

public function __construct($data=array()) {

if (isset($data['id'])) $this->id = (int) $data['id'];

if (isset($data['publicationDate'])) $this->publicationDate = (int) $data['publicationDate'];

if (isset($data['title'])) $this->title = $data['title'];

if (isset($data['summary'])) $this->summary = $data['summary'];

if (isset($data['content'])) $this->content = $data['content'];

}

/**

* Sets the object's properties using the edit form post values in the supplied array

*

* @param assoc The form post values

*/

public function storeFormValues ($params) {

// Store all the parameters

$this->__construct($params);

// Parse and store the publication date

if (isset($params['publicationDate'])) {

$publicationDate = explode ('-', $params['publicationDate']);

if (count($publicationDate) == 3) {

list ($y, $m, $d) = $publicationDate;

$this->publicationDate = mktime (0, 0, 0, $m, $d, $y);

}

}

}

/**

* Returns an Article object matching the given article ID

*

* @param int The article ID

* @return Article|false The article object, or false if the record was not found or there was a problem

*/

public static function getById($id) {

$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);

$sql = "SELECT *, UNIX_TIMESTAMP(publicationDate) AS publicationDate FROM articles WHERE id = :id";

$st = $conn->prepare($sql);

$st->bindValue(":id", $id, PDO::PARAM_INT);

$st->execute();

$row = $st->fetch();

$conn = null;

if ($row) return new Article($row);

}

/**

* Returns all (or a range of) Article objects in the DB

*

* @param int Optional The number of rows to return (default=all)

* @param string Optional column by which to order the articles (default="publicationDate DESC")

* @return Array|false A two-element array : results => array, a list of Article objects; totalRows => Total number of articles

*/

public static function getList($numRows=1000000, $order="publicationDate DESC") {

$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);

$sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) AS publicationDate FROM articles

ORDER BY " . mysql_escape_string($order) . " LIMIT :numRows";

$st = $conn->prepare($sql);

$st->bindValue(":numRows", $numRows, PDO::PARAM_INT);

$st->execute();

$list = array();

while ($row = $st->fetch()) {

$article = new Article($row);

$list[] = $article;

}

// Now get the total number of articles that matched the criteria

$sql = "SELECT FOUND_ROWS() AS totalRows";

$totalRows = $conn->query($sql)->fetch();

$conn = null;

return (array ("results" => $list, "totalRows" => $totalRows[0]));

}

/**

* Inserts the current Article object into the database, and sets its ID property.

*/

public function insert() {

// Does the Article object already have an ID?

if (!is_null($this->id)) trigger_error ("Article::insert(): Attempt to insert an Article object that already has its ID property set (to $this- >id).", E_USER_ERROR);

// Insert the Article

$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);

$sql = "INSERT INTO articles (publicationDate, title, summary, content ) VALUES (FROM_UNIXTIME(:publicationDate), :title, :summary, :content)";

$st = $conn->prepare ($sql);

$st->bindValue(":publicationDate", $this->publicationDate, PDO::PARAM_INT);

$st->bindValue(":title", $this->title, PDO::PARAM_STR);

$st->bindValue(":summary", $this->summary, PDO::PARAM_STR);

$st->bindValue(":content", $this->content, PDO::PARAM_STR);

$st->execute();

$this->id = $conn->lastInsertId();

$conn = null;

}

/**

* Updates the current Article object in the database.

*/

public function update() {

// Does the Article object have an ID?

if (is_null($this->id)) trigger_error ("Article::update(): Attempt to update an Article object that does not have its ID property set.", E_USER_ERROR);

// Update the Article

$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);

$sql = "UPDATE articles SET publicationDate=FROM_UNIXTIME(:publicationDate), title=:title, summary=:summary, content=:content WHERE id = :id";

$st = $conn->prepare ($sql);

$st->bindValue(":publicationDate", $this->publicationDate, PDO::PARAM_INT);

$st->bindValue(":title", $this->title, PDO::PARAM_STR);

$st->bindValue(":summary", $this->summary, PDO::PARAM_STR);

$st->bindValue(":content", $this->content, PDO::PARAM_STR);

$st->bindValue(":id", $this->id, PDO::PARAM_INT);

$st->execute();

$conn = null;

}

/**

* Deletes the current Article object from the database.

*/

public function delete() {

// Does the Article object have an ID?

if (is_null($this->id)) trigger_error ("Article::delete(): Attempt to delete an Article object that does not have its ID property set.", E_USER_ERROR);

// Delete the Article

$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);

$st = $conn->prepare ("DELETE FROM articles WHERE id = :id LIMIT 1");

$st->bindValue(":id", $this->id, PDO::PARAM_INT);

$st->execute();

$conn = null;

}

}

?>

+0

逃离或使用图书馆可能会删除HTML代码更好的解决办法是使用BASE64_ENCODE –

+2

显示您从DB中插入和检索的PHP代码。 –

+0

我添加了php代码。 @Barmar –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值