LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-29-2005, 02:44 PM   #1
benrose111488
Member
 
Registered: Jun 2004
Location: Wantage, NJ
Distribution: Fedora 7
Posts: 177

Rep: Reputation: 30
Simple PHP Script


Hey, I'm writing code for my own forum, and I need a script that changes line-breaks into <BR> tags. The code:

PHP Code:
$replybody=preg_replace("\n","<br>",$replybody); 
Does not work... Does anyone have any ideas? Anything would be appreciated.

Thanks.
 
Old 01-29-2005, 02:46 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Try it as an expression:
$replybody=preg_replace("/\n/","<br>",$replybody);
 
Old 01-29-2005, 02:48 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Unless you want to figure it out yourself as a practice...
PHP already provides a function for this: nl2br().
 
Old 01-29-2005, 02:52 PM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
Or try str_replace instead of preg_replace...
 
Old 01-29-2005, 03:02 PM   #5
benrose111488
Member
 
Registered: Jun 2004
Location: Wantage, NJ
Distribution: Fedora 7
Posts: 177

Original Poster
Rep: Reputation: 30
Awesome, I tried the nl2br tag (sorry, it seemed the easiest lol) and it worked.

Now, another question begs to be asked. When I try to translate HTML into plaintext, I'm using the code

PHP Code:
$replybody=preg_replace("<","<",$replybody); 
However, this code results in this on the actual posting page:
Warning: No ending matching delimiter '>' found in /drive2/fpgshttpd/speakfree/forum/replyinsert.php on line 156

Now, remember, I don't want to DELETE the tags, I want to simply make them so a browser won't recognize them as tags. I thought that replacing the < symbol with it's HTML code would accomplish that... but apparently it doesn't.

Any ideas?

Thanks again
 
Old 01-30-2005, 02:12 PM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
Try replacing it with &lt; and &gt; instead.

Edit: Also, you are still using preg_replace in that but not using a regular expression for your pattern. Either convert that to a regular expression or use str_replace. Or maybe there is some other sort of HTML encoding function in PHP as well.

Last edited by deiussum; 01-30-2005 at 02:28 PM.
 
Old 01-30-2005, 05:19 PM   #7
benrose111488
Member
 
Registered: Jun 2004
Location: Wantage, NJ
Distribution: Fedora 7
Posts: 177

Original Poster
Rep: Reputation: 30
Okay, schweet, got that working, thanks

Now, here's the thing. I have this forum and I want people to have the ability to upload their own avatar. I want the avatar to be stored in an SQL table, but I don't think this is at all feasible. I saw something about the SQL type "blob" being able to hold images and such, but if I wanted to make a table like

USERNAME | AVATAR

and have AVATAR actually hold the physical image rather than a link to the image, would that be possible at all? And what about delivery to the HTML page? Could a PHP variable be an image? I'm just so confused about how to make this work effectively. If you have any idea at all, please let me know

Thanks again for everything
 
Old 01-31-2005, 01:39 PM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
You can store the image contents in a blog field.

To display the image you probably want to create a second php file called "avatar.php" which is called from the image's src tag and takes a parameter like "user=123", you can then lookup user 123's image and send it back to the browser.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
a Simple help on PHP Script Gerardoj Programming 1 10-18-2004 08:26 PM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM
Simple php script with html form not working. sinsoush Programming 4 04-01-2004 08:02 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM


All times are GMT -5. The time now is 05:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration