php html file writing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

php html file writing

Post 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>
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Try using stripslashes before you write things to the file.
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

<font \

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

It appears you're sending your message via $_GET

try urlencode() on the string, and then to read it, use urldecode()
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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']));
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

ok it works but

Post by X3no »

Does anyone have a php script that will delete all html tags,php,javascript,ect from a given string?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

htmlentities(), strip_tags()
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

Thanks

Post by X3no »

Thanks that was exactly what I needed.
but what do i need htmlentities for?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply