jesushax Posted June 17, 2008 Share Posted June 17, 2008 hi heres my function 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); } $data = str_replace("<br /><br />","</p><p>",$data); $data = str_replace("<br />","",$data); $data = str_replace("<p>","</p><p>",$data); $data = str_replace("</p></p><p>","</p><p>",$data); $data = str_replace("</p><p></p><p>","</p><p>",$data); return($data); } and $Brief = paragraphs($_POST["txtBrief"]); and the result is <p class="MsoNormal"><span color="#000000">Vivergo Fuels Ltd is a new company created to build and operate a wheat to bioethanol production facility based at the BP site, Saltend, <place w:st="on" />East Yorkshire</place />. <p /></span></p><p /><p /> my form field is using a wysiwyg editor but that shouldnt affect the function that runs after the text is posted should it? the striptags function is supposed to strip all but <p> tags how is it letting all that through? CHeers Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/ Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 just checking out the strip tags function <?php $data ='<p>testing <a href="dog">dig</a> <span>sausages</span></p><br /> doggy '; strip_tags($data, "<p></p>"); echo $data; ?> that should output :<p> testing dig sausages </p>doggy it outputted: <p>testing <a href="dog">dig</a> <span>sausages</span></p><br /> doggy this mean the strip_tags function doesnt work on my host? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567097 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 u need to ... echo strip_tags($data, "<p></p>"); Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567099 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 echo strip_tags($data); Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567102 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 echoing it works... but i wont be able to use that function will as i want to remove the first and last <p> tags i need a way to put the new echoed data into a variable so i can strip those first and last tags any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567105 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 <?php $data ='<p>testing <a href="dog">dig</a> <span>sausages</span></p><br /> doggy '; $dat=strip_tags($data); echo $dat; ?> $dat=strip_tags($data, "<p></p>"); is used to allow <p></p> tags Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567112 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 yes i want the <p> tags in it for example i want: <p>text, <br />text,<span> text</p><p>text, <a href>text, text</p> to become text, text, text</p><p>text, text, text i want to remove all html apart from the <p></p> tags then take out the first <p> and last </p> i cant echo it too cos i want to insert it into db Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567116 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 <?php $data ='<p>text, text,<span> text</p><p>text, <a href>text</a>, text</p> '; $dat=strip_tags($data,'<p>'); echo $dat; ?> it will output text, text, text text, text, text Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567118 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 ive managed to figure it out now i just needed the order changing function paragraphs($data) { if(substr($data, 0,3) == '<p>') { $data = substr($data, 3);} if(substr($data, -4) == '</p>'){ $data = substr($data, 0, -4);} $data = str_replace("<p>","</p><p>",$data); echo strip_tags($data, "<p></p>"); } this works but how can i now get the value you into variable to post to datbase i cant echo to put into a db can i Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567121 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 its the sample code i ve written....is tis ur looking for??? <? class gan{ function paragraphs($data) { if(substr($data, 0,3) == '<p>') { $data = substr($data, 3);} if(substr($data, -4) == '</p>'){ $data = substr($data, 0, -4);} $data = str_replace("<p>","</p><p>",$data); $dat=strip_tags($data, "<p></p>"); return $dat; } } $hai='<p>text, text,<span> text</p><p>text, <a href>text</a>, text</p> '; $gan=new gan(); $jai=$gan->paragraphs($hai); echo $jai; ?> Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567123 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 tried putting your code into practice got this error Catchable fatal error: Object of class gan could not be converted to string in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 175 this is my 175 $SQL = $SQL."ClientCase='$Case', ClientResult='$Result', ClientBrief='$Brief', ClientServices='$Services', ClientCommentsTitle='$CommentsTitle', ClientComments='$Comments', PortDateEdited='$Date' WHERE PortID='$PortID' "; Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567135 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 i got it working with this code ....im my database i can able to insert the values text,text,...... class gan{ function paragraphs($data) { if(substr($data, 0,3) == '<p>') { $data = substr($data, 3);} if(substr($data, -4) == '</p>'){ $data = substr($data, 0, -4);} $data = str_replace("<p>","</p><p>",$data); $dat=strip_tags($data, "<p></p>"); return $dat; } } $hai='<p>text, text,<span> text</p><p>text, <a href>text</a>, text</p> '; $gan=new gan(); $jai=$gan->paragraphs($hai); $jais= trim ($jai); $sql=mysql_query("insert into tablename(fieldname)values('$jais')"); Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567143 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 how is your sql structured? Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567145 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 CREATE TABLE `user` ( `id` int(11) NOT NULL auto_increment, `nickname` varchar(50) default NULL, `password` varchar(50) default NULL, `status` text, `created_at` datetime default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ; Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567157 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 not your table your sql my sql is $SQL = "UPDATE tblPortfolio Set PortType='$Type', ClientCompany='$Company', ProjectTitle='$ProjectTitle', ClientName='$Name', ClientUrl='$URL', ClientLocation='$Location', "; if (!empty($Logo)) { $SQL = $SQL."ClientLogo='$Logo', "; } $SQL = $SQL."ClientCase='$Case', ClientResult='$Result', ClientBrief='$Brief', ClientServices='$Services', ClientCommentsTitle='$CommentsTitle', ClientComments='$Comments', PortDateEdited='$Date' WHERE PortID='$PortID' "; and i get Catchable fatal error: Object of class gan could not be converted to string in /home/fhlinux153/c/cwservicesltd.co.uk/user/htdocs/admin/portfolio/edit_project.php on line 175 Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567159 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 can u show ur code Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567162 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 class gan{ function paragraphs($data) { if(substr($data, 0,3) == '<p>') { $data = substr($data, 3);} if(substr($data, -4) == '</p>'){ $data = substr($data, 0, -4);} $data = str_replace("<p>","</p><p>",$data); $data = str_replace("</p></p><p>","</p><p>",$data); $dat=strip_tags($data, "<p></p>"); return $dat; } } $PortID = $_POST["txtID"]; $Type = $_POST["SelType"]; $Company = $_POST["txtCompany"]; $ProjectTitle = $_POST["txtProjectTitle"]; $Name = $_POST["txtName"]; $URL = $_POST["txtUrl"]; $Location = $_POST["txtLocation"]; $Logo = $_FILES['pictures']['name'][0]; $Image1 = $_FILES['pictures']['name'][1]; $Image2 = $_FILES['pictures']['name'][2]; $Image3 = $_FILES['pictures']['name'][3]; $Case = $gan=new gan(); $jai=$gan->paragraphs($_POST["txtCase"]); $Result = $gan=new gan(); $jai=$gan->paragraphs($_POST["txtResult"]); $Brief = $gan=new gan(); $jai=$gan->paragraphs($_POST["txtBrief"]); $CommentsTitle = $_POST["txtCommentsTitle"]; $Comments = $gan=new gan(); $jai=$gan->paragraphs($_POST["txtComments"]); $Date = date("Y-m-d"); if (!empty($_POST["chkXHTML"])) { $Services = ":".$_POST["chkXHTML"].":";} if (!empty($_POST["chkMembership"])) { $Services = $Services.":".$_POST["chkMembership"].":";} if (!empty($_POST["chkEvent"])) { $Services = $Services.":".$_POST["chkEvent"].":";} if (!empty($_POST["ChkOffice"])) { $Services = $Services.":".$_POST["ChkOffice"].":";} if (!empty($_POST["chkCMS"])) { $Services = $Services.":".$_POST["chkCMS"].":";} if (!empty($_POST["chkBranding"])) { $Services = $Services.":".$_POST["chkBranding"].":";} if (!empty($_POST["ChkCopy"])) { $Services = $Services.":".$_POST["ChkCopy"].":";} if (!empty($_POST["ChkSupport"])) { $Services = $Services.":".$_POST["ChkSupport"].":";} if (!empty($_POST["chkOnlineDB"])) { $Services = $Services.":".$_POST["chkOnlineDB"].":";} if (!empty($_POST["chkConsult"])) { $Services = $Services.":".$_POST["chkConsult"].":";} if (!empty($_POST["ChkPrint"])) { $Services = $Services.":".$_POST["ChkPrint"].":";} if (!empty($_POST["ChkPC"])) { $Services = $Services.":".$_POST["ChkPC"].":";} if (!empty($_POST["chkPDF"])) { $Services = $Services.":".$_POST["chkPDF"].":";} if (!empty($_POST["ChkPR"])) { $Services = $Services.":".$_POST["ChkPR"].":";} if (!empty($_POST["ChkNetwork"])) { $Services = $Services.":".$_POST["ChkNetwork"].":";} if (!empty($_POST["ChkFault"])) { $Services = $Services.":".$_POST["ChkFault"].":";} $SQL = "UPDATE tblPortfolio Set PortType='$Type', ClientCompany='$Company', ProjectTitle='$ProjectTitle', ClientName='$Name', ClientUrl='$URL', ClientLocation='$Location', "; if (!empty($Logo)) { $SQL = $SQL."ClientLogo='$Logo', "; } if (!empty($Image1)) { $SQL = $SQL."PortImage1='$Image1', "; } if (!empty($Image2)) { $SQL = $SQL."PortImage2='$Image2', "; } if (!empty($Image3)) { $SQL = $SQL."PortImage3='$Image3', "; } $SQL = $SQL."ClientCase='$Case', ClientResult='$Result', ClientBrief='$Brief', ClientServices='$Services', ClientCommentsTitle='$CommentsTitle', ClientComments='$Comments', PortDateEdited='$Date' WHERE PortID='$PortID' "; mysql_query($SQL) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567165 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 my bad i structured it wrong, its uploading now still not doing what i want it to do, but i might be able to figure the rest out cheeers Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567171 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 right my last stage is to remove classes from it at the mo the wysiwyg editor uploads these <p class="MsoNormal"> i need to change <p class="MsoNormal"> to <p> and the class name may be differnet to "MsoNormal" i think i know how its done but dont know how to do it CHeers Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567172 Share on other sites More sharing options...
zenag Posted June 17, 2008 Share Posted June 17, 2008 change these line of code: $Result = $gan=new gan(); $jai=$gan->paragraphs($_POST["txtResult"]); To: $gan=new gan(); $Case=$gan->paragraphs($_POST["txtCase"]); and so on........ Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567174 Share on other sites More sharing options...
jesushax Posted June 17, 2008 Author Share Posted June 17, 2008 yes i saw that and fixed it, thanks im trying to do something else now, as above ^ do you know how i can do such a thing? such as $data = str_replace('<p class=" anything in here ">',"<p>",$data); thanks Quote Link to comment https://forums.phpfreaks.com/topic/110540-solved-still-having-trouble-with-function/#findComment-567177 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.