[thelist] writing a variable to file in PHP

Steve Webster steve at netbreed.co.uk
Tue Jan 7 15:01:14 CST 2003


Hi Tom,

> I'm dynamically writing a PHP file that has some variables in it. Two
> of my opening lines are thus:
> ---------------------
> $body  = "<?\n";
> $body .= "$connect = mysql_connect 'ip', 'login', 'pw');\n";
> ---------------------
>
> When I open my generated file, I only get:
>
> ---------------------
>  = @mysql_connect('127.0.0.1', 'moshe', 'silvermysql');
> ---------------------
>
> For some reason it is *I think* trying to write the value of
> $connect. How can I avoid this so it gets written out as a variable?
> I figured since it was inside the string it would, but then PHP does
> parse vars inside a string...help!

You're quite right about why you're getting the output you are, and to
get around it all you have to do is to escape the dollar symbol thusly:

$body .= "\$connect = ...";

I hope this helps!

Regards,

Steve

--

================================
  Steve Webster
  Freelance Web Developer
  steve at codejunkie.co.uk

  PHP, MySQL, Flash, Perl + more
  http://www.codejunkie.co.uk
================================





More information about the thelist mailing list