|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Showing code ???
I created a very primative site management system for myself. Keep in mind that I am still a NooB with PHP.
What I am trying to do is Create an article where I talk about something I did, then I show the code of what i did. Currently it all goes into a mysql table. when I put in the following 'echo "this is code"; ' into the table i just see what was supposed to be echo'ed. i dont see 'echo' How could I put in html code into the db and display it without having all the html code on 1 line. thats what happened when i used htmlspecialchars(). Can someone tell me how devarticles.com(this wonderful site) show the code highlighted in yellow ? THANKS MUCH !!! |
|
#2
|
|||
|
|||
|
To get the code (and article contents) spaced out as you write them, you need to convert your new-line-feed characters to "<br/>" tags. I am not sure the exact code for this in PHP, but it would be a simple replace command.
|
|
#3
|
|||
|
|||
|
The easiest way would be to replace < with < and > with >
PHP Code:
This is one way of doing it. And the function that replaces /n with <br /> is nl2br(). Also for more info check str_replace(). |
|
#4
|
|||
|
|||
|
you could then do something like
PHP Code:
that should highlight everything that is inside the $article var in yellow..... ps.. welcome to the forums!! ![]() |
|
#5
|
|||
|
|||
|
Or you could use highlight_string() (http://www.php.net/manual/en/functi...ight-string.php) which does all the hard work for you!
Hadley |
|
#6
|
|||
|
|||
|
Ok. First let me say THANKS. But I have another question:
if i have the var $article= to the following code -> PHP Code:
however, when I echo the $article var out, everything is on 1 line like this: <?php echo "first line"; echo "second line"; echo "third line"; ?> How can I keep the same format as the top code ??? Thanks again |
|
#7
|
|||
|
|||
|
It was already mentioned a bit higher up. Use nl2br().
PHP Code:
How about now? |
|
#8
|
|||
|
|||
|
YES !!! that worked.
it is working great. THANK YOU !!! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Showing code ??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|