-   Programming (
-   -   Simple PHP Script (

benrose111488 01-29-2005 03:44 PM

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:


Does not work... Does anyone have any ideas? Anything would be appreciated.


david_ross 01-29-2005 03:46 PM

Try it as an expression:

Hko 01-29-2005 03:48 PM

Unless you want to figure it out yourself as a practice...
PHP already provides a function for this: nl2br().

deiussum 01-29-2005 03:52 PM

Or try str_replace instead of preg_replace...

benrose111488 01-29-2005 04:02 PM

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:


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

deiussum 01-30-2005 03:12 PM

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.

benrose111488 01-30-2005 06:19 PM

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


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

david_ross 01-31-2005 02:39 PM

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.

All times are GMT -5. The time now is 12:47 PM.