Using fwrite with variables attached

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
lunny
Forum Newbie
Posts: 13
Joined: Mon Feb 19, 2007 8:33 am

Using fwrite with variables attached

Post by lunny »

Hi,

I am trying work with fwrite() to write some information to a seperate URL from a php page. I am trying to send a variable with some data but this isnt working for me.

For example

$fp = fopen($filename, 'w+');
fwrite($fp,"<?php
$test = 'Hello';
?>");

It doesnt work I get parse errors any ideas why ?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

assign the var with a heredoc then write the var?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Double quote string and variables not escaped.
lunny
Forum Newbie
Posts: 13
Joined: Mon Feb 19, 2007 8:33 am

Post by lunny »

can you expand on what you mean by that please? - double quote strings and variables not escaped??? perhaps an example.. thank you..
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

He means that this:

"<?php $test = 'Hello'; ?>"

should be:

"<?php \$test = 'Hello'; ?>"
Post Reply