PDA

View Full Version : have a question about php




Novark
Dec 20, 2005, 10:49 AM
i don't have a mac but it seem like there was lots of help here.

this question is about php:
i want to know how to get rid of the \ befor every '.

now i will give you the situation:
i have made it so my firend can update his news on his webpage throught the browser . i made it so he inputs the date and i writes it to a file and then he inputs the new news and then it writes to another file and then he puts in his sig and i puts in into a nother file. then he sends it. the files then are taken into seperate arrays, then i used the implode functio to change them to strings then i brought the old news into an array, then i used the array_unshift to add all the new information into the old news, then i used the implode function on that, then i wrote over the file with the new string i hade which included the old news and the new news.

then the file is read into a seperate page
when it comes up on the page if i hade "wasn't" it would come up as "wasn\'t". what can i do to stop that from happening?



floyde
Dec 20, 2005, 12:57 PM
Have you tried storing your ' as " ? Not sure that would work though, I've never used PHP, but I think it's something along those lines. Or use a replace function to get rid of them.

Novark
Dec 20, 2005, 01:16 PM
this is the main code im using

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Put in the date:
<br>
<input type="text" name="date" size="20">
<br>
<input type="submit" name="submit1" value="Save Date">
</form>

<?php

//check for submit1
if(isset($_POST['submit1'])){
//set file to open'
$filedate = 'gndate.txt';
//open the file
$fhdate = fopen($filedate, 'w') or die('could not open the file');
//write to the file
fwrite($fhdate, "<hr>".$_POST['date']."<br />\n") or die('could not write to the file');
//close the file
fclose($fhdate);
}

?>

<br>
<br>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Put in the text you want entered
<br>
<textarea rows="20" name="textchange" cols="40">
</textarea>
<br>
<input type="submit" name="submit2" value="Add Entry">
</form>

<?php

//check for submit2
if(isset($_POST['submit2'])){
//set file to open
$filetext = 'gntext.txt';
//open the file
$fhtext = fopen($filetext, 'a') or die('could not open the file');
//write to the file
fwrite($fhtext, "<br /><img src=\"Pictures/Goldchip.gif\" width=\"10\" height=\"10\">\n".$_POST['textchange']."<br />\n");
//close the file
fclose($fhtext);
}

?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit4" value="Erase text file">
</form>

<?php


//check for submit4
if(isset($_POST['submit4'])){
//set file to open
$fileerase = 'gntext.txt';
//open the file
$fherase = fopen($fileerase, 'w') or die('could not open the file');
//erase the file
fwrite($fherase) or die('could not write the file');
//close the file
fclose($fherase);
}

?>


<br>
<br>


<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Put in you sig
<br>
<input type="text" name="sig" size="20">
<br>
<input type="submit" name="submit3" value="Save Sig">
</form>

<?php


//check for submit3
if(isset($_POST['submit3'])){
//set the file to open
$filesig = 'gnsig.txt';
//open the file
$fhsig = fopen($filesig, 'w') or die('could not open the file');
//write the file
fwrite($fhsig, "<br /><div align=\"right\">".$_POST['sig']."</div>\n") or die('could not write the file');
//close the file
fclose($fhsig);
}

?>


<br>
<br>
<br>


<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="submit5" value="SEND">
</form>

<?php


//check for SEND
if(isset($_POST['submit5'])){
//set files
$add1 = 'gndate.txt';
$add2 = 'gntext.txt';
$add3 = 'gnsig.txt';
$addto = 'gnews.txt';
//open the files to add
$dataadd1 = file($add1) or die('could not oopen the file');
$dataadd2 = file($add2) or die('could not oopen the file');
$dataadd3 = file($add3) or die('could not oopen the file');
$dataaddto = file($addto) or die('could not oopen the file');
//implode the arrays to be added
$newadd1 = implode(' ', $dataadd1);
$newadd2 = implode(' ', $dataadd2);
$newadd3 = implode(' ', $dataadd3);
//add them to the news
array_unshift($dataaddto, $newadd3);
array_unshift($dataaddto, $newadd2);
array_unshift($dataaddto, $newadd1);
//implode the news array
$newaddto = implode(' ', $dataaddto);
//set the file to add the new news to
$finalnews = 'gnews.txt';
//open the file
$fhfinalnews = fopen($finalnews, 'w') or die('could not open the file');
//write the final news
fwrite($fhfinalnews, $newaddto) or die('could not write to the file');
//close the file
fclose ($fhfinalnews);


//open files
$senderase1 = 'gndate.txt';
$senderase2 = 'gntext.txt';
$senderase3 = 'gnsig.txt';
//open the files
$fhsenderase1 = fopen($senderase1, 'w') or die('could not open the file');
$fhsenderase2 = fopen($senderase2, 'w') or die('could not open the file');
$fhsenderase3 = fopen($senderase3, 'w') or die('could not open the file');
//erase the files
fwrite($fhsenderase1) or die('could not write the file');
fwrite($fhsenderase2) or die('could not write the file');
fwrite($fhsenderase3) or die('could not write the file');
//close the files
fclose($fhsenderase1);
fclose($fhsenderase2);
fclose($fhsenderase3);
}


?>


<br>
<b><u>PRIVEW</u></b>
<br>
This is what you have so far:


<?php


//set the file to open
$readdate = 'gndate.txt';
//open the file
$readdatadate = file($readdate) or die('<br />nothing in the file\'s');
//read the fileinto the browser
foreach ($readdatadate as $readdateline){
echo $readdateline;
}


//set the file to open
$readtext = 'gntext.txt';
//open the file
$readdatatext = file($readtext) or die('<br />nothing in the file\'s');
//read the file into the bowser
foreach ($readdatatext as $readtextline){
echo $readtextline;
}


//set the file to open
$readsig = 'gnsig.txt';
//open the file
$readdatasig = file($readsig) or die('<br />nothing in the file\'s');
//read the file into the browser
foreach ($readdatasig as $readsigline){
echo $readsigline;
}


?>

as you can see i have no control when and where the " ' " comes in, it is all up to the user, when he types it in is whne it is put in there so i can't isolate them all and change it into &quote.

this is the websight where i have it set up: http://members.lycos.co.uk/phpsight1101/

superbovine
Dec 20, 2005, 02:47 PM
stripslashes is your friend. You should also read about magic_quote on php.net it goes quote well with stripslashes and doing mysql work.

http://us3.php.net/manual/en/function.stripslashes.php


<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

Novark
Dec 20, 2005, 09:15 PM
thank you soo much it works and it is my new friend