Hi everyone i am looking for a way to get code that i have imputed into the database and maintain the formatting the problem i am having is if i insert code into the database like show below.
<?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
)
);
When pulling it back out from the database to view it will view as shown below no spaces just one massive block off text/code no formatting. i want it to show as formmatted code so i can copy and past开发者_StackOverflow社区e the code.
<?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 ) );
Not sure what you saying, but it sounds like you are storing PHP in a database, which is an interesting idea...
Anyway, you'll want to make sure you escape newlines before storing (i.e. replace them with a \n).
When you render it, stick it in a pre tag to ensure that they show up on a webpage, or use nl2br.
before to store you can encode the code snippets using base64_encode. If you retrive data back to user you can decode it by base64_decode. Arman.
精彩评论