Page 1 of 1

php html file writing

Posted: Wed Aug 29, 2007 7:10 pm
by X3no
I have this php script:

Code: Select all

<?php
if (!$_GET['message']){exit("no chat posted!");}
$message=$_GET['message'];
$filecont=file_get_contents("chat.html");
$file=fopen('chat.html','w');
fwrite($file,$message.'<br>'.$filecont);
fclose($file);
echo "chat sent";
?>
I am using it to write specified messages to an html file.
I am trying to use give it the string
<img src='/emotes/frown.gif' width='22' height='22'>
but it writes this to the file:
<img src=\'/emotes/frown.gif\' width=\'22\' height=\'22\'>
and then I using
<font color='#080808'>
but i get
<font color=\'\\<br>

Posted: Wed Aug 29, 2007 7:29 pm
by toasty2
Try using stripslashes before you write things to the file.

<font \

Posted: Wed Aug 29, 2007 7:54 pm
by X3no
i do this
and now im getting this.
<font='<br>
The '#' is causing some kind of problem in the $_GET['message'] part

I did the stripslashes() to get rid of the slashes though

And the in the img tag the "=" is gone and a "\" is in its place even after running stripslashes.

Posted: Wed Aug 29, 2007 8:03 pm
by s.dot
It appears you're sending your message via $_GET

try urlencode() on the string, and then to read it, use urldecode()

Posted: Wed Aug 29, 2007 8:08 pm
by X3no
scottayy wrote:It appears you're sending your message via $_GET

try urlencode() on the string, and then to read it, use urldecode()
So were do I put this?

Posted: Wed Aug 29, 2007 8:30 pm
by s.dot

Code: Select all

http://url/script.php?message=<?php echo urlencode($message_string); ?>
then

Code: Select all

if (!empty($_GET['message']))
{
    $message = urldecode(stripslashes($_GET['message']));
}

ok it works but

Posted: Wed Aug 29, 2007 8:39 pm
by X3no
Does anyone have a php script that will delete all html tags,php,javascript,ect from a given string?

Posted: Wed Aug 29, 2007 9:37 pm
by s.dot
htmlentities(), strip_tags()

Thanks

Posted: Wed Aug 29, 2007 9:44 pm
by X3no
Thanks that was exactly what I needed.
but what do i need htmlentities for?

Posted: Wed Aug 29, 2007 9:50 pm
by s.dot
In case you want the html to show up as plain text.

You don't have to worry about php code, as it will just be read as plain text, unless for some reason you eval() it (which I doubt you are doing).