PDA

View Full Version : Messing with php


Zozart
15-03-2004, 22:46
Okay, I've been messing around with file-changing functions with PHP and all is well except for one thing.

I have this for my form:
<form action='end.php' method='POST'>
<input type='text' name='user'>
<?php br(3); ?>
<textarea name='text' rows='5' cols='40'></textarea>
<?php br(3); ?>

<?php br(3); ?>
<input type='submit' value='Okay'>
</form>

And that works okay, then on the recieving end I've written this:
$file = "data.zyon";
if (!file_exists($file))
die("Error: File does not exist");

$fi = fopen($file,"a+");
$text.="<p class='spacer' />";
fwrite($fi,$text);
$size = filesize($file);
fclose($fi);
@include "$file";

And, as I expected, that outputs the contents of the newly written zyon.data file.

But there's one problem.. When I try to use punctuation (most noticablely apostrophies), php automatically seems to insert a \ in front of them.

I can recollect that \ is used to escape characters, but I can't figure out why php is throwing it in here.

So any answers as to why, and preferably, how to remove it, would be appreciated, thanks :D

shifty.ricky
16-03-2004, 00:51
stripslashes()

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

Zozart
16-03-2004, 01:51
Thanks mate.

Clarksy
16-03-2004, 13:35
PHP escapes string characters so when the content is loaded into a string it doesnt break the syntax...

your text file without any escape slashes:

This is "some text" in quotes


Now, imagine a php string with this text file's content. It would look like the example below which would raise a syntax error:

$text="This is "some text" in quotes"

It should read:

$text="This is \"some text\" in quotes"


Thats why PHP is saving the string with escape codes.