PDA

View Full Version : Code Area



Titan85
05-27-2007, 09:26 PM
Ok, I am trying to figure out how to make something allow this to be put in a page:
<?php
echo 'Some Code';
?>I see it used to post tutorials a lot and I am making a tutorial management script with authoring capabilities, but I can't figure this out. I would appreciate any help. Thanks in advance

djr33
05-27-2007, 09:57 PM
That code is VERY basic and will simply be parsed as "Some Code", with no linebreaks, etc., just placed where it is in the source code of the html.
What exactly is unclear about using that?

To use PHP at all, you must 1. have it installed on the server, 2. have it enabled, 3. have it parsed as PHP, meaning that the page must end with .php or you must have another extension set (perhaps with .htaccess) to be parsed as php, but that is usually more trouble than it's worth.

thetestingsite
05-27-2007, 10:02 PM
Actually, I think he was referring to making a tutorial type page with blocks that look like so:



<?php
echo 'This is the code snippet that is highlighted and displayed';
?>


(or anything placed between the [PHP] tags in this forum as well as some other forums).


The way that is accomplished is by using highlight_string() (http://us2.php.net/manual/en/function.highlight-string.php) and displaying that on the page in between whatever other tags you want (<div>, <table>, etc).

Hope this helps.

Titan85
05-27-2007, 10:38 PM
Thats exactly what I need, testingsite. Just one more thing, do you have any suggestions on how I can implement this in a user friendly manner. Like some way of it reading what part should be code and then putting highlight_string() around it? Thanks for the help

thetestingsite
05-27-2007, 10:42 PM
Probably the best way would be to use bbcode (any tags that you specify), then use either preg_replace (http://us2.php.net/manual/en/function.preg-replace.php) or str_replace (http://us2.php.net/manual/en/function.str-replace.php) to create the proper formatting for that tag.

Hope this helps.

djr33
05-27-2007, 10:59 PM
Ah, very interesting.
I thought that question was too easy.

thetestingsite
05-28-2007, 01:46 AM
I thought that question was too easy.

I thought so too the first time I read it. I went back and reread it a few more times just to comprehend it.

Titan85
05-28-2007, 01:56 AM
Sorry about not making it to clear. Thanks for all the help

djr33
05-28-2007, 02:40 AM
Ha, well, I know you've worked with PHP before, so that's why I went into the detail on possible issues, though I couldn't figure out why you were back to such basics :D

As for the latest question, BB code is a good answer.

Titan85
05-28-2007, 11:54 PM
Ha, well, I know you've worked with PHP before, so that's why I went into the detail on possible issues, though I couldn't figure out why you were back to such basics :D

As for the latest question, BB code is a good answer.Yeah, I read it again myself and saw how it came across wrong. :)