General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 23rd, 2003, 08:39 PM
david_jata david_jata is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 david_jata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to david_jata
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 !!!

Reply With Quote
  #2  
Old June 24th, 2003, 12:08 AM
wes wes is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 24 wes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old June 24th, 2003, 03:26 AM
_rainbow_ _rainbow_ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Lj, Slovenia
Posts: 27 _rainbow_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 28 sec
Reputation Power: 0
The easiest way would be to replace < with < and > with >

PHP Code:
// the artcle is the variable that holds the text you want to insert
// into MySQL database.
$article str_replace("<","<",$article);
$article str_replace(">",">",$article); 


This is one way of doing it. And the function that replaces /n with <br /> is nl2br(). Also for more info check str_replace().

Reply With Quote
  #4  
Old June 24th, 2003, 03:37 AM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
you could then do something like

PHP Code:
echo '<font style="background-color: #FFFF00">';
echo 
$article;
echo 
'</font>'


that should highlight everything that is inside the $article var in yellow.....

ps.. welcome to the forums!!
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #5  
Old June 24th, 2003, 04:49 AM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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

Reply With Quote
  #6  
Old June 24th, 2003, 01:39 PM
david_jata david_jata is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 david_jata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to david_jata
Ok. First let me say THANKS. But I have another question:

if i have the var $article= to the following code ->
PHP Code:
<?php
echo "first line";
echo 
"second line";
echo 
"third line";
?>


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

Reply With Quote
  #7  
Old June 24th, 2003, 04:30 PM
_rainbow_ _rainbow_ is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Lj, Slovenia
Posts: 27 _rainbow_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 28 sec
Reputation Power: 0
It was already mentioned a bit higher up. Use nl2br().

PHP Code:
 $article nl2br($article);
// then insert it into your MySQL table 


How about now?

Reply With Quote
  #8  
Old June 24th, 2003, 04:58 PM
david_jata david_jata is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 3 david_jata User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to david_jata
YES !!! that worked.
it is working great.

THANK YOU !!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Showing code ???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT