jesushax Posted June 13, 2008 Share Posted June 13, 2008 hi below is my function f unction paragraphs($data) { $data = str_replace('<br />', '', $data); $data = preg_replace('%\A\s*<p>|</p>\s*\z%', '', $data); htmlspecialchars($data); } $Case = paragraphs($_POST["txtCase"]); i didnt create the function code i just sued it but the idea of the code is to remove the <p> if the data sent has one at the begining remove the </p> if the data has one at the end remove all <br /> tags thanks for any help at the moment the function posts nothing, blank data only... Quote Link to comment Share on other sites More sharing options...
Orio Posted June 13, 2008 Share Posted June 13, 2008 htmlspecialchars($data); //Should become: return htmlspecialchars($data); Orio. Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 13, 2008 Author Share Posted June 13, 2008 thanks a bunch Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 13, 2008 Author Share Posted June 13, 2008 just looking at the code function paragraphs($data) { $data = str_replace('<br />', '', $data); $data = preg_replace('%\A\s*<p>|</p>\s*\z%', '', $data); return htmlspecialchars($data); ) htmlspecialchars converts say > to > but i want the <p></p> html tags in the middle i just want the ones removed from the end and the begining if there are any if there arent do dont anything, the code above do this? Quote Link to comment Share on other sites More sharing options...
Vizor Posted June 13, 2008 Share Posted June 13, 2008 You could use strip_tags() and then add <p> and </p> to the beginning and end of your text. Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 13, 2008 Author Share Posted June 13, 2008 but i want to keep <p></p> tags in the middle of my text i dont want wht wones at the begninig strip tags would keep them all wouldnt it? Quote Link to comment Share on other sites More sharing options...
Orio Posted June 13, 2008 Share Posted June 13, 2008 Use the optional $allowable_tags parameter: strip_tags($data, "<p>") This won't strip <p> tags. Orio. Quote Link to comment Share on other sites More sharing options...
Vizor Posted June 13, 2008 Share Posted June 13, 2008 Sorry, I didn't read your post properly. well, one thing you could do is: <?php $text = '<p>This is some text. <p>Another paragraph</p> Some more text</p>'; if(substr($text, 0,3) == '<p>' && substr($text, -4) == '</p>') { $text = substr($text, 3); $text = substr($text, 0, -4); } echo $text; ?> Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 13, 2008 Author Share Posted June 13, 2008 ok heres my finale, this good? strip_tags($data, "<p>") if(substr($data, 0,3) == '<p>' && substr($data, -4) == '</p>') { $data = substr($data, 3); $data = substr($data, 0, -4); str_replace("<p>","</p><p>",$data); echo $data; so all other html will be stripped apart from <p> tags then if it begins or ends with <p> it will be removed then any <p> inside the text will be replaced with </p><p> what about symbols like & and ' they come up as & etc.. are they classed as html tags will they be stripped? Thanks Quote Link to comment Share on other sites More sharing options...
jesushax Posted June 13, 2008 Author Share Posted June 13, 2008 final one is here function paragraphs($data) { strip_tags($data, "<p>") if(substr($data, 0,3) == '<p>' && substr($data, -4) == '</p>') { $data = substr($data, 3); $data = substr($data, 0, -4); } str_replace("<p>","</p><p>",$data); str_replace("</p><p></p><p>","</p><p>",$data); echo $data; } this work well? 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.