Jump to content

[SOLVED] still having trouble with function


jesushax

Recommended Posts

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

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

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

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

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;

?>

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' ";

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')");



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 ;


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

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());

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.