0

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>

Edited by moivet: n/a

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by moivet
0

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...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.