Hi!

This code should replace <br> or <br /> between certain elements in text posted in textarea element.

I use nl2br for detection of new line. That function also adds <br /> between html elements...for example <table><br><tr> elements...

Code works fine, but...
When used multiple column table, code "eats" all columns, and leaves only one column.
Same thing is when list(<ul>) is used. Example code:
<ul>
<li>first</li>
<li>second</li>
</ul>
Code removes <br>, and <br /> elements, and also this row <li>second</li>, and returns
<ul>
<li>first</li>
</ul>

Help!!!!!!!

<?php

$pocetak = array('<table>', '<table.*?>', '<table>', '<table.*?>', '<tr>', '<tr.*?>', '<tr>', '<tr.*?>', '<\/td>', '<\/td>', '<\/td>','<\/tr>', '<ul>', '<\/li>', '<\/li>', '<ol>', '<\/li>', '<\/li>');

$kraj = array('<tr>', '<tr>', '<tr.*?>', '<tr.*?>', '<td>', '<td>', '<td.*?>', '<td.*?>', '<\/tr>', '<td>', '<td.*?>', '<\/table>', '<li>', '<li>', '<\/ul>', '<li>', '<li>', '<\/ol>');

$broj_radnji = count($pocetak);
$z = 0;
S
if ($_POST['su']) {
$tekst = nl2br($_POST['te']);
while ($z != $broj_radnji) {
$tekst = preg_replace('#('.$pocetak[$z].')(.*?)('.$kraj[$z].')#si', '$1'.''.'$3', $tekst);
$z++;
}
echo $tekst.'<br>';
}

?>
<form action="proba_preg.php" method="post">
<textarea name="te" style="height:200px; width:250px"></textarea>
<input type="submit" name="su">
</form>

I've solved problem with column/list removal...
It was problem with last two elements of table/list in array. But now, this code can't remove <br> <br /> between that two elements.
Suggestions...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.