gpt4 book ai didi

php - 数据库格式化

转载 作者:行者123 更新时间:2023-11-29 14:52:00 25 4
gpt4 key购买 nike

大家好,我正在寻找一种方法来获取已输入数据库的代码并维护格式,我遇到的问题是如果我将代码插入数据库,如下所示。

    <?php
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'blackwood_services',
array(
'labels' => array(
'name' => __( 'BW Services' ),
'singular_name' => __( 'BW Services' )
),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpts', 'revisions') //the editing regions that will support

)
);

当从数据库中将其拉出进行查看时,它将如下所示查看,没有空格,只有一大块文本/代码,没有格式。我希望它显示为格式化代码,以便我可以复制并粘贴代码。

<?php add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'blackwood_services', array( 'labels' => array( 'name' => __( 'BW Services' ), 'singular_name' => __( 'BW Services' ) ), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array( 'title',   'editor', 'thumbnail', 'excerpts', 'revisions') //the editing regions that will support ) ); 

最佳答案

不确定你在说什么,但听起来你正在将 PHP 存储在数据库中,这是一个有趣的想法......

无论如何,您需要确保在存储之前转义换行符(即用\n 替换它们)。

渲染时,将其粘贴在预标记中以确保它们显示在网页上,或使用 nl2br。

关于php - 数据库格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5536661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com