jesushax Posted June 12, 2008 Share Posted June 12, 2008 ok so heres my example <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse purus enim, gravida et, dictum sed, cursus id, tellus </p><p><br /> Nunc sodales consequat dui. Pellentesque faucibus ligula et dui. Suspendisse potenti. Vivamus sit amet ligula. Aenean pulvinar imperdiet enim. Nam aliquam purus. </p> the paragrahs and breaks will be in different positions sometimes but what i want to do is remove all <br /> from the submitted text and remove the the <p> if the submitted text begins with one and remove the </p> if the submitted text ends with one and only keep </p><p> if there is one so remove all <br /> remove first <p> remove last </p> keep </p><p> cheerss Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 12, 2008 Share Posted June 12, 2008 I'm sure there's an easier way, but I like complex (call me a freak.....) <?php $code="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse purus enim, gravida et, dictum sed, cursus id, tellus </p><p><br /> Nunc sodales consequat dui. Pellentesque faucibus ligula et dui. Suspendisse potenti. Vivamus sit amet ligula. Aenean pulvinar imperdiet enim. Nam aliquam purus. </p>"; $code = str_replace("<br />", "", $code); $code_array = str_split($code); $code_count = count($code_array); $count = $code_count - 4; $count_p = $count++; if ($code_array[0] == "<" && ($code_array[1] == "p" || $code_array[1] == "P")){ unset($code_array[0]); unset($code_array[1]); unset($code_array[2]); $code_count = count($code_array); $count = $code_count - 1; if ($code_array[$count] == "<" && $code_array[$count + 1] == "/"){ unset($code_array[$code_count]); ++$code_count; unset($code_array[$code_count]); $code_count++; unset($code_array[$code_count]); $code_count++; unset($code_array[$code_count]); array_pop($code_array); } $code = implode($code_array); } elseif ($code_array[$count - 1] == "<" && $code_array[$count] == "/"){ array_pop($code_array); array_pop($code_array); array_pop($code_array); array_pop($code_array); $code = implode($code_array); } print $code; ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted June 12, 2008 Share Posted June 12, 2008 <pre> <?php $data = <<<DATA <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse purus enim, gravida et, dictum sed, cursus id, tellus </p><p><br /> Nunc sodales consequat dui. Pellentesque faucibus ligula et dui. Suspendisse potenti. Vivamus sit amet ligula. Aenean pulvinar imperdiet enim. Nam aliquam purus. </p> DATA; $data = str_replace('<br />', '', $data); $data = preg_replace('%\A\s*<p>|</p>\s*\z%', '', $data); echo htmlspecialchars($data); ?> </pre> Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 12, 2008 Author Share Posted June 12, 2008 thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.