Can't figure out this ereg problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gijs
Forum Commoner
Posts: 53
Joined: Wed Aug 28, 2002 4:05 am
Location: Belgium

Can't figure out this ereg problem

Post by gijs »

Hi,

In my Admin section I use a 3 files to insert, edit and delete "items" into the database.
item_insert.php: a simple form that is posted to item.php
item_edit.php: a form that retrieves the data from the selected item
item.php: contains the logic for inserting, updating and deleting an item.

When I use "caridge return" when inserting a new item it converts it to < /br> which is ok.

But the strange phenomenon I'm experiencing is that when I edit the item afterwards and save it into the database all the existing < /br> are duplicated.

What am I doing wrong ??

Here is the code I use in for the textarear in items_insert.php:

Code: Select all

// Conversion of end_of_page-marks in news_main to HTML end_of_page-marks 
         $_POST&#1111;'item_text'] = nl2br($_POST&#1111;'item_text']); 
         $_POST&#1111;'item_text'] = eregi_replace("\n", "", $_POST&#1111;'item_text']);

Here is the code I use in item.php in a switch-statement, before the data is inserted or updated in the database:

Code: Select all

// Conversion of the <br>-tags tot end_of_line 
$items&#1111;'item_text'] = eregi_replace('<br&#1111;&#1111;:space:]]$/?&#1111;&#1111;:space:]]*>', "/n", $items&#1111;'item_text']);
Some help would be much appreciated !

Thanks in advance,

Gijs
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

Try something like this:

Code: Select all

<?php
eregi_replace("\n\r", "<br>", $items['item_text'])
?>
Personally, I just leave the new lines and returns in the database. I only replace them when they are being viewed as text (ie--not in a <textarea>).
User avatar
gijs
Forum Commoner
Posts: 53
Joined: Wed Aug 28, 2002 4:05 am
Location: Belgium

Post by gijs »

Thanks,

I solved my own mystery ...
As I'm updating existing data containing <br /> the nl2br-fucntion will add the extra tags.
Have to solve it in another way.

Gijs
Post Reply