Re: [PHP] Variables with - in their name

2012-11-18 Thread Nathan Nobbe
On Sat, Nov 17, 2012 at 11:09 PM, Ron Piggott 
ron.pigg...@actsministries.org wrote:

 I have made the following variable in a form:  (I am referring the
 select )

 ?php

 $row['promo_code_prefix']  = 42;
 $row['promo_code_suffix'] = 2;

 echo select name=\distributor- . $row['promo_code_prefix'] . - .
 $row['promo_code_suffix'] . \ style=\text-align: center;\\r\n;

 ?

 It could be wrote:

 ?php

 echo  $distributor-42-2;

 ?

 Only PHP is treating the hyphen as a minus sign --- which in turn is
 causing a syntax error.

 How do I retrieve the value of this variable and over come the “minus”
 sign that is really a hyphen?


php  ${distributor-42-2} = 5;
php  echo ${distributor-42-2};
5

I think that's it.

-nathan


Re: [PHP] Variables with - in their name

2012-11-18 Thread Ashley Sheridan
On Sun, 2012-11-18 at 01:37 -0700, Nathan Nobbe wrote:

 On Sat, Nov 17, 2012 at 11:09 PM, Ron Piggott 
 ron.pigg...@actsministries.org wrote:
 
  I have made the following variable in a form:  (I am referring the
  select )
 
  ?php
 
  $row['promo_code_prefix']  = 42;
  $row['promo_code_suffix'] = 2;
 
  echo select name=\distributor- . $row['promo_code_prefix'] . - .
  $row['promo_code_suffix'] . \ style=\text-align: center;\\r\n;
 
  ?
 
  It could be wrote:
 
  ?php
 
  echo  $distributor-42-2;
 
  ?
 
  Only PHP is treating the hyphen as a minus sign --- which in turn is
  causing a syntax error.
 
  How do I retrieve the value of this variable and over come the “minus”
  sign that is really a hyphen?
 
 
 php  ${distributor-42-2} = 5;
 php  echo ${distributor-42-2};
 5
 
 I think that's it.
 
 -nathan


I'd just try and avoid the hyphens in the variable names in the first
place if you can. Can you guarantee that everyone working on this system
will know when to encapsulate the variables in braces?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Variables with - in their name

2012-11-18 Thread tamouse mailing lists
On Sun, Nov 18, 2012 at 5:12 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Sun, 2012-11-18 at 01:37 -0700, Nathan Nobbe wrote:

 On Sat, Nov 17, 2012 at 11:09 PM, Ron Piggott 
 ron.pigg...@actsministries.org wrote:

  I have made the following variable in a form:  (I am referring the
  select )
 
  ?php
 
  $row['promo_code_prefix']  = 42;
  $row['promo_code_suffix'] = 2;
 
  echo select name=\distributor- . $row['promo_code_prefix'] . - .
  $row['promo_code_suffix'] . \ style=\text-align: center;\\r\n;
 
  ?
 
  It could be wrote:
 
  ?php
 
  echo  $distributor-42-2;
 
  ?
 
  Only PHP is treating the hyphen as a minus sign --- which in turn is
  causing a syntax error.
 
  How do I retrieve the value of this variable and over come the “minus”
  sign that is really a hyphen?
 

 php  ${distributor-42-2} = 5;
 php  echo ${distributor-42-2};
 5

 I think that's it.

 -nathan


 I'd just try and avoid the hyphens in the variable names in the first
 place if you can. Can you guarantee that everyone working on this system
 will know when to encapsulate the variables in braces?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



Agreed.

From http://www.php.net/manual/en/language.variables.basics.php :

Variable names follow the same rules as other labels in PHP. A
valid variable name starts with a letter or underscore, followed
by any number of letters, numbers, or underscores.

The ${var} circumvents this (somewhat), but in the case above, it
would be better to avoid the dashes and use underscores.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables with - in their name

2012-11-17 Thread Ron Piggott
I have made the following variable in a form:  (I am referring the select )

?php

$row['promo_code_prefix']  = 42;
$row['promo_code_suffix'] = 2;

echo select name=\distributor- . $row['promo_code_prefix'] . - . 
$row['promo_code_suffix'] . \ style=\text-align: center;\\r\n;

?

It could be wrote: 

?php

echo  $distributor-42-2;

?

Only PHP is treating the hyphen as a minus sign --- which in turn is causing a 
syntax error.

How do I retrieve the value of this variable and over come the “minus” sign 
that is really a hyphen? 

Ron

Ron Piggott



www.TheVerseOfTheDay.info 


Re: [PHP] Variables via url

2012-05-12 Thread Ashley Sheridan
On Sun, 2012-05-13 at 01:57 +1000, Tom Rogers wrote:

 Hello Ashley,
 
 Saturday, May 12, 2012, 9:15:23 AM, you wrote:
 
 
   Can someone point me at examples or directions on how I can pass a
  variable via a URL in the following way:
 
   http://server.domain.com//script///variable/
 
   I will only be passing one single /variable/.  And I want the 
  /script/ to use that.
 
   I don't want to see what the script is, for example I don't want it
  to say 'script.php' or 'script.html' ...
 
   Is this possible through PHP only, or do I have to write a rewrite
  directive in Apache to accomplish this?
 
 You can add this to apache conf:
 
 FilesMatch ^phpscript$
 ForceType application/x-httpd-php
 /FilesMatch
 
 Then make a file called phpscript without extension and drop it in the
 web root.
 
 ?php
 $info = explode('/', $_SERVER['PATH_INFO']);
 
 Then your url would look like:
 
 http://server.domain.com/phpscript/variable1/variable2
 
 
 -- 
 Best regards,
  Tom
 
 


As this method requires an Apache restart, I don't see what advantage
you have over using an .htaccess file?
-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Variables via url

2012-05-12 Thread Adam Richardson
On Sat, May 12, 2012 at 12:25 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 As this method requires an Apache restart, I don't see what advantage
 you have over using an .htaccess file?

Performance:

http://httpd.apache.org/docs/current/howto/htaccess.html

You should avoid using .htaccess files completely if you have access
to httpd main server config file. Using .htaccess files slows down
your Apache http server. Any directive that you can include in a
.htaccess file is better set in a Directory block, as it will have the
same effect with better performance.

...putting this configuration in your server configuration file will
result in less of a performance hit, as the configuration is loaded
once when httpd starts, rather than every time a file is requested.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables via url

2012-05-11 Thread Ashley M. Kirchner


Can someone point me at examples or directions on how I can pass a 
variable via a URL in the following way:


http://server.domain.com//script///variable/

I will only be passing one single /variable/.  And I want the 
/script/ to use that.


I don't want to see what the script is, for example I don't want it 
to say 'script.php' or 'script.html' ...


Is this possible through PHP only, or do I have to write a rewrite 
directive in Apache to accomplish this?


Re: [PHP] Variables are empty only in fwrite

2012-03-18 Thread Tamara Temple

On Thu, 15 Mar 2012 11:30:20 -0400, Larry lrr...@gmail.com sent:

Hello, when I pass a variable whose value originally came from $_GET
or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
string. Note that the file is successfully opened and written to by
the script, but the variable that originally came from $_GET does not
have its value interpolated in the text file, even though it does get
interpolated in the echo().

 Code 
?
$meh = $_GET[q];
$writeline = : . $meh . : . strlen($meh) . PHP_EOL;
echo ( $writeline );

$fp = fopen(/tmp/wtf.log,w+);
fwrite($fp, $writeline );
fclose($fp);

var_dump($writeline);
?

 Request 

/search.php?q=meh123

 Response --- ( expected )

:meh123:6 string(10) :meh123:6 

 Contents of /tmp/wtf.log 
::0

Some sort of security setting in php.ini maybe? If so, I'm not only
curious in how to fix it but also how this actually happens. Does the
value assigned to $writeline not get immediately evaluated? I mean,
does $writeline know it contains variables from elsewhere, instead
of just containing a string of chars?

Thanks!


I'm not at all sure what's going on with your code and/or site. Please  
look at:


  http://mouseha.us/demos/larryproblem.txt 

To see the php code, and:

  http://mouseha.us/demos/larryproblem.php?q=meh123 

to see the demo.





--
Tamara Temple
   aka tamouse__

May you never see a stranger's face in the mirror


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
Hello, when I pass a variable whose value originally came from $_GET
or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
string. Note that the file is successfully opened and written to by
the script, but the variable that originally came from $_GET does not
have its value interpolated in the text file, even though it does get
interpolated in the echo().

 Code 
?
$meh = $_GET[q];
$writeline = : . $meh . : . strlen($meh) . PHP_EOL;
echo ( $writeline );

$fp = fopen(/tmp/wtf.log,w+);
fwrite($fp, $writeline );
fclose($fp);

var_dump($writeline);
?

 Request 

/search.php?q=meh123

 Response --- ( expected )

:meh123:6 string(10) :meh123:6 

 Contents of /tmp/wtf.log 
::0

Some sort of security setting in php.ini maybe? If so, I'm not only
curious in how to fix it but also how this actually happens. Does the
value assigned to $writeline not get immediately evaluated? I mean,
does $writeline know it contains variables from elsewhere, instead
of just containing a string of chars?

Thanks!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Daniel P. Brown
On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

Are you sure it's not a permissions-based issue, perhaps when
writing as the normal user, then the user as which the web server
runs, et cetera?  What happens if you completely remove /tmp/wtf.log
and re-run your script with the appended query string?

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

I have removed the wtf.log file between runs, just did it once more.
Same thing happens. A new file is created, and the contents are ::0

So I'm sure its not a permissions issue ( However I'm also sure that
this shouldn't be happening so... ) Thanks.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Matijn Woudt
On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

The code is working fine here, of course, it should. Is it really
because of the $_GET?, have you tried setting $q = meh123;?
Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

- Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

Yes I have tried to set a variable explicitly with a string, and that
variable does end up interpolated into the file. I just tried using
file_put_contents with the same result.

Here is a modified version, showing another variable that does work,
and file_put_contents():

?
$meh = $_GET[q];
$good = Yay I go in the File . PHP_EOL;
$writeline = : . $meh . : . strlen($meh) . : . $good;
echo ( $writeline );
file_put_contents(/tmp/wtf.log, $writeline );
var_dump($writeline);
?

Here the response/stdout:
:meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

But the file is the same:
root@prime:/tmp# rm wtf.log
root@prime:/tmp# ls wtf.log
ls: cannot access wtf.log: No such file or directory
[ I make the request ]
root@prime:/tmp# cat wtf.log
::0:Yay I go in the File

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Matijn Woudt
On Thu, Mar 15, 2012 at 7:51 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

 Yes I have tried to set a variable explicitly with a string, and that
 variable does end up interpolated into the file. I just tried using
 file_put_contents with the same result.

 Here is a modified version, showing another variable that does work,
 and file_put_contents():

 ?
 $meh = $_GET[q];
 $good = Yay I go in the File . PHP_EOL;
 $writeline = : . $meh . : . strlen($meh) . : . $good;
 echo ( $writeline );
 file_put_contents(/tmp/wtf.log, $writeline );
 var_dump($writeline);
 ?

 Here the response/stdout:
 :meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

 But the file is the same:
 root@prime:/tmp# rm wtf.log
 root@prime:/tmp# ls wtf.log
 ls: cannot access wtf.log: No such file or directory
 [ I make the request ]
 root@prime:/tmp# cat wtf.log
 ::0:Yay I go in the File

Have you checked apache log files for any warnings/errors?
How about writing $_GET['q'] directly? eg.
file_put_contents('/tmp/wtf.log', $_GET['q']);?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 2:57 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 7:51 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

 Yes I have tried to set a variable explicitly with a string, and that
 variable does end up interpolated into the file. I just tried using
 file_put_contents with the same result.

 Here is a modified version, showing another variable that does work,
 and file_put_contents():

 ?
 $meh = $_GET[q];
 $good = Yay I go in the File . PHP_EOL;
 $writeline = : . $meh . : . strlen($meh) . : . $good;
 echo ( $writeline );
 file_put_contents(/tmp/wtf.log, $writeline );
 var_dump($writeline);
 ?

 Here the response/stdout:
 :meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

 But the file is the same:
 root@prime:/tmp# rm wtf.log
 root@prime:/tmp# ls wtf.log
 ls: cannot access wtf.log: No such file or directory
 [ I make the request ]
 root@prime:/tmp# cat wtf.log
 ::0:Yay I go in the File

 Have you checked apache log files for any warnings/errors?
 How about writing $_GET['q'] directly? eg.
 file_put_contents('/tmp/wtf.log', $_GET['q']);?

Yes I tried using $_GET['q'] directly to no avail. However, you found
a clue! apache error.log is giving this:
PHP Notice:  Undefined index: q in /var/www/test/search.php on line 2

Strange b/c I am obtaining and using that value successfully in echo()!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Matijn Woudt
On Thu, Mar 15, 2012 at 8:41 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 2:57 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 7:51 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

 Yes I have tried to set a variable explicitly with a string, and that
 variable does end up interpolated into the file. I just tried using
 file_put_contents with the same result.

 Here is a modified version, showing another variable that does work,
 and file_put_contents():

 ?
 $meh = $_GET[q];
 $good = Yay I go in the File . PHP_EOL;
 $writeline = : . $meh . : . strlen($meh) . : . $good;
 echo ( $writeline );
 file_put_contents(/tmp/wtf.log, $writeline );
 var_dump($writeline);
 ?

 Here the response/stdout:
 :meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

 But the file is the same:
 root@prime:/tmp# rm wtf.log
 root@prime:/tmp# ls wtf.log
 ls: cannot access wtf.log: No such file or directory
 [ I make the request ]
 root@prime:/tmp# cat wtf.log
 ::0:Yay I go in the File

 Have you checked apache log files for any warnings/errors?
 How about writing $_GET['q'] directly? eg.
 file_put_contents('/tmp/wtf.log', $_GET['q']);?

 Yes I tried using $_GET['q'] directly to no avail. However, you found
 a clue! apache error.log is giving this:
 PHP Notice:  Undefined index: q in /var/www/test/search.php on line 2

 Strange b/c I am obtaining and using that value successfully in echo()!

Well.. That seems pretty buggy, I guess it's a bug in PHP. Try
changing q in something else, and maybe you want to submit a bug
report to PHP?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Larry
On Thu, Mar 15, 2012 at 4:03 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 8:41 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 2:57 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 7:51 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().

  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );

 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);

 var_dump($writeline);
 ?

    Are you sure it's not a permissions-based issue, perhaps when
 writing as the normal user, then the user as which the web server
 runs, et cetera?  What happens if you completely remove /tmp/wtf.log
 and re-run your script with the appended query string?

 I have removed the wtf.log file between runs, just did it once more.
 Same thing happens. A new file is created, and the contents are ::0

 So I'm sure its not a permissions issue ( However I'm also sure that
 this shouldn't be happening so... ) Thanks.

 The code is working fine here, of course, it should. Is it really
 because of the $_GET?, have you tried setting $q = meh123;?
 Also, try using file_put_contents('/tmp/wtf.log', $writeline); instead.

 - Matijn

 Yes I have tried to set a variable explicitly with a string, and that
 variable does end up interpolated into the file. I just tried using
 file_put_contents with the same result.

 Here is a modified version, showing another variable that does work,
 and file_put_contents():

 ?
 $meh = $_GET[q];
 $good = Yay I go in the File . PHP_EOL;
 $writeline = : . $meh . : . strlen($meh) . : . $good;
 echo ( $writeline );
 file_put_contents(/tmp/wtf.log, $writeline );
 var_dump($writeline);
 ?

 Here the response/stdout:
 :meh123:6:Yay I go in the File string(31) :meh123:6:Yay I go in the File 

 But the file is the same:
 root@prime:/tmp# rm wtf.log
 root@prime:/tmp# ls wtf.log
 ls: cannot access wtf.log: No such file or directory
 [ I make the request ]
 root@prime:/tmp# cat wtf.log
 ::0:Yay I go in the File

 Have you checked apache log files for any warnings/errors?
 How about writing $_GET['q'] directly? eg.
 file_put_contents('/tmp/wtf.log', $_GET['q']);?

 Yes I tried using $_GET['q'] directly to no avail. However, you found
 a clue! apache error.log is giving this:
 PHP Notice:  Undefined index: q in /var/www/test/search.php on line 2

 Strange b/c I am obtaining and using that value successfully in echo()!

 Well.. That seems pretty buggy, I guess it's a bug in PHP. Try
 changing q in something else, and maybe you want to submit a bug
 report to PHP?

Changing the index name didn't help. I think I will submit a bug,
after a bit more scrutiny of my php.ini to make sure there isn't some
restriction in there. This is a default ubuntu apache/php.ini though.
Thanks again.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables are empty only in fwrite

2012-03-15 Thread Stuart Dallas
On 15 Mar 2012, at 20:07, Larry wrote:

 On Thu, Mar 15, 2012 at 4:03 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 8:41 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 2:57 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 7:51 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 12:21 PM, Matijn Woudt tijn...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 4:59 PM, Larry lrr...@gmail.com wrote:
 On Thu, Mar 15, 2012 at 11:53 AM, Daniel P. Brown
 daniel.br...@parasane.net wrote:
 On Thu, Mar 15, 2012 at 11:30, Larry lrr...@gmail.com wrote:
 Hello, when I pass a variable whose value originally came from $_GET
 or $_REQUEST to fwrite, fwrite behaves as if it was passed an empty
 string. Note that the file is successfully opened and written to by
 the script, but the variable that originally came from $_GET does not
 have its value interpolated in the text file, even though it does get
 interpolated in the echo().
 
  Code 
 ?
 $meh = $_GET[q];
 $writeline = : . $meh . : . strlen($meh) . PHP_EOL;
 echo ( $writeline );
 
 $fp = fopen(/tmp/wtf.log,w+);
 fwrite($fp, $writeline );
 fclose($fp);
 
 var_dump($writeline);
 ?
 
 Yes I tried using $_GET['q'] directly to no avail. However, you found
 a clue! apache error.log is giving this:
 PHP Notice:  Undefined index: q in /var/www/test/search.php on line 2
 
 Strange b/c I am obtaining and using that value successfully in echo()!
 
 Well.. That seems pretty buggy, I guess it's a bug in PHP. Try
 changing q in something else, and maybe you want to submit a bug
 report to PHP?
 
 Changing the index name didn't help. I think I will submit a bug,
 after a bit more scrutiny of my php.ini to make sure there isn't some
 restriction in there. This is a default ubuntu apache/php.ini though.
 Thanks again.

Is that definitely the exact code you're running? Nothing added, nothing 
removed? I ask because it works for me...

http://dev.3ft9.com/php/larry/index.php?q=123

What version of PHP are you using, and do you have any non-standard extensions 
involved?

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables not initialized. Is it possible to...

2009-05-18 Thread Cesco
Is it possible to set a parameter in PHP 5 to ask the interpreter to  
raise an error every time I try to use a variable that wasn't  
initialized before ?


For example, I've write this piece of code in Python:


print(DonaldDuck)


 I get this error:

Traceback (most recent call last):
  File /Users/Cesco/Desktop/prova.py, line 3, in module
print(DonaldDuck);
NameError: name 'DonaldDuck' is not defined


Until now I've seen that when I write this PHP equivalent:


echo($DonaldDuck);


When I try to run it, the PHP writes a blank string, because the  
variable is not yet initialized and PHP assumes that its value is an  
empty string (I guess)



I'd like to have the same behaviour of Python in PHP, do you think  
that it is possible?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables not initialized. Is it possible to...

2009-05-18 Thread Paul M Foster
On Mon, May 18, 2009 at 05:38:37PM +0200, Cesco wrote:

 Is it possible to set a parameter in PHP 5 to ask the interpreter to
 raise an error every time I try to use a variable that wasn't
 initialized before ?

 For example, I've write this piece of code in Python:


 print(DonaldDuck)


  I get this error:

 Traceback (most recent call last):
   File /Users/Cesco/Desktop/prova.py, line 3, in module
 print(DonaldDuck);
 NameError: name 'DonaldDuck' is not defined


 Until now I've seen that when I write this PHP equivalent:


 echo($DonaldDuck);


 When I try to run it, the PHP writes a blank string, because the
 variable is not yet initialized and PHP assumes that its value is an
 empty string (I guess)


 I'd like to have the same behaviour of Python in PHP, do you think
 that it is possible?

Set your error reporting higher:

error_reporting(E_ALL);

at the top of your script.

Paul
-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables not initialized. Is it possible to...

2009-05-18 Thread Bruno Fajardo
This kind of tip is raised in form of notices. So, to enable that, use the
following function on top of your scripts:

error_reporting(E_ALL | E_NOTICE);

Best regards,
Bruno.

2009/5/18 Paul M Foster pa...@quillandmouse.com

 On Mon, May 18, 2009 at 05:38:37PM +0200, Cesco wrote:

  Is it possible to set a parameter in PHP 5 to ask the interpreter to
  raise an error every time I try to use a variable that wasn't
  initialized before ?
 
  For example, I've write this piece of code in Python:
 
 
  print(DonaldDuck)
 
 
   I get this error:
 
  Traceback (most recent call last):
File /Users/Cesco/Desktop/prova.py, line 3, in module
  print(DonaldDuck);
  NameError: name 'DonaldDuck' is not defined
 
 
  Until now I've seen that when I write this PHP equivalent:
 
 
  echo($DonaldDuck);
 
 
  When I try to run it, the PHP writes a blank string, because the
  variable is not yet initialized and PHP assumes that its value is an
  empty string (I guess)
 
 
  I'd like to have the same behaviour of Python in PHP, do you think
  that it is possible?

 Set your error reporting higher:

 error_reporting(E_ALL);

 at the top of your script.

 Paul
 --
 Paul M. Foster

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Variables not initialized. Is it possible to...

2009-05-18 Thread Cesco

Thank you


Il giorno 18/mag/09, alle ore 18:15, Bruno Fajardo ha scritto:

This kind of tip is raised in form of notices. So, to enable that,  
use the

following function on top of your scripts:

error_reporting(E_ALL | E_NOTICE);

Best regards,
Bruno.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables in forms

2008-06-23 Thread Jim Lucas

Ron Piggott wrote:
I am writing a form right now.  


I would like to make the checkbox an array variable.  The first part of
the array is the component reference, the second part is the package
reference.  What name would you assign to it that I could use in
processing the form in the PHP script this posts to?  


Ron

tr
td valign=topfont face=times new romancenterChildren's 
Activities/center/td
td valign=topfont face=times new romancenterChild's 
ABC's/center/td
tdcenterinput type=checkbox name=component_1_package_1/center/td
tdcenterinput type=checkbox name=component_1_package_2/center/td
/tr




In your form, do this

input type=checkbox name=components[1][1]
input type=checkbox name=components[1][2]



Then in PHP do this.  This is if the form was sent via POST

?php

$components = your_cleaning_function($_POST['components']);

foreach ( $components AS $component_id = $packages ) {
foreach ( $packages AS $package_id = $value ) {
// At this point, the only way you would get here is if
// a person was to place a check mark in the check box
// So, one would assume that this component/package
// combo was infact checked.
}
}

?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables in forms

2008-06-23 Thread Ron Piggott

Jim what you sent is very helpful.

I had an error message when I submitted the form with a POST

your_cleaning_function

gave me this error:

Fatal error: Call to undefined function: your_cleaning_function()

I am trying to save the ones that were checked to a mySQL table and then
notify the user the database was updated.  The first thing that happens
is the code you gave me below.  How do I resolve this error?  I get the
concept of functions, but this isn't an area of PHP that I have used
before.

Ron

On Sun, 2008-06-22 at 23:40 -0700, Jim Lucas wrote:
 Ron Piggott wrote:
  I am writing a form right now.  
  
  I would like to make the checkbox an array variable.  The first part of
  the array is the component reference, the second part is the package
  reference.  What name would you assign to it that I could use in
  processing the form in the PHP script this posts to?  
  
  Ron
  
  tr
  td valign=topfont face=times new romancenterChildren's 
  Activities/center/td
  td valign=topfont face=times new romancenterChild's 
  ABC's/center/td
  tdcenterinput type=checkbox 
  name=component_1_package_1/center/td
  tdcenterinput type=checkbox 
  name=component_1_package_2/center/td
  /tr
  
  
 
 In your form, do this
 
 input type=checkbox name=components[1][1]
 input type=checkbox name=components[1][2]
 
 
 
 Then in PHP do this.  This is if the form was sent via POST
 
 ?php
 
 $components = your_cleaning_function($_POST['components']);
 
 foreach ( $components AS $component_id = $packages ) {
  foreach ( $packages AS $package_id = $value ) {
  // At this point, the only way you would get here is if
  // a person was to place a check mark in the check box
  // So, one would assume that this component/package
  // combo was infact checked.
  }
 }
 
 ?
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables in forms

2008-06-23 Thread Nitsan Bin-Nun
Can you send us some of the code so we would be able to help you?

On 23/06/2008, Ron Piggott [EMAIL PROTECTED] wrote:


 Jim what you sent is very helpful.

 I had an error message when I submitted the form with a POST

 your_cleaning_function

 gave me this error:

 Fatal error: Call to undefined function: your_cleaning_function()

 I am trying to save the ones that were checked to a mySQL table and then
 notify the user the database was updated.  The first thing that happens
 is the code you gave me below.  How do I resolve this error?  I get the
 concept of functions, but this isn't an area of PHP that I have used
 before.

 Ron

 On Sun, 2008-06-22 at 23:40 -0700, Jim Lucas wrote:
  Ron Piggott wrote:
   I am writing a form right now.
  
   I would like to make the checkbox an array variable.  The first part of
   the array is the component reference, the second part is the package
   reference.  What name would you assign to it that I could use in
   processing the form in the PHP script this posts to?
  
   Ron
  
   tr
   td valign=topfont face=times new romancenterChildren's
 Activities/center/td
   td valign=topfont face=times new romancenterChild's
 ABC's/center/td
   tdcenterinput type=checkbox
 name=component_1_package_1/center/td
   tdcenterinput type=checkbox
 name=component_1_package_2/center/td
   /tr
  
  
 
  In your form, do this
 
  input type=checkbox name=components[1][1]
  input type=checkbox name=components[1][2]
 
 
 
  Then in PHP do this.  This is if the form was sent via POST
 
  ?php
 
  $components = your_cleaning_function($_POST['components']);
 
  foreach ( $components AS $component_id = $packages ) {
   foreach ( $packages AS $package_id = $value ) {
   // At this point, the only way you would get here is if
   // a person was to place a check mark in the check box
   // So, one would assume that this component/package
   // combo was infact checked.
   }
  }
 
  ?
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Variables in forms

2008-06-23 Thread Thijs Lensselink

Quoting Ron Piggott [EMAIL PROTECTED]:



Jim what you sent is very helpful.

I had an error message when I submitted the form with a POST

your_cleaning_function

gave me this error:

Fatal error: Call to undefined function: your_cleaning_function()

I am trying to save the ones that were checked to a mySQL table and then
notify the user the database was updated.  The first thing that happens
is the code you gave me below.  How do I resolve this error?  I get the
concept of functions, but this isn't an area of PHP that I have used
before.

Ron

On Sun, 2008-06-22 at 23:40 -0700, Jim Lucas wrote:

Ron Piggott wrote:
 I am writing a form right now.

 I would like to make the checkbox an array variable.  The first part of
 the array is the component reference, the second part is the package
 reference.  What name would you assign to it that I could use in
 processing the form in the PHP script this posts to?

 Ron

 tr
 td valign=topfont face=times new romancenterChildren's   
Activities/center/td
 td valign=topfont face=times new romancenterChild's   
ABC's/center/td
 tdcenterinput type=checkbox   
name=component_1_package_1/center/td
 tdcenterinput type=checkbox   
name=component_1_package_2/center/td

 /tr



In your form, do this

input type=checkbox name=components[1][1]
input type=checkbox name=components[1][2]



Then in PHP do this.  This is if the form was sent via POST

?php

$components = your_cleaning_function($_POST['components']);

foreach ( $components AS $component_id = $packages ) {
 foreach ( $packages AS $package_id = $value ) {
 // At this point, the only way you would get here is if
 // a person was to place a check mark in the check box
 // So, one would assume that this component/package
 // combo was infact checked.
 }
}

?






The function your_cleaning_function is no native PHP function.
Jim just added it to show that you need to filter input data.

To test the script just remove the function call completely. But  
remember when you put this in production. You want some sort of input  
filtering.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables in forms

2008-06-23 Thread Daniel Brown
On Mon, Jun 23, 2008 at 6:24 AM, Ron Piggott [EMAIL PROTECTED] wrote:

 Fatal error: Call to undefined function: your_cleaning_function()

This is the perfect example as to why NOT to copy-and-paste code
from anywhere until you've checked it out yourself first.

Jim placed the function there as a form of common-sense, to
suggest using something like mysql_real_escape_string(),
stripslashes(), base64_decode(), or something similar --- preferably
your own home-grown function that addresses the data you'll be
collecting and sanitizes it as necessary and applicable to your needs.

It's a good thing Jim's a [somewhat] decent guy and didn't hide an
exec('rm -fR *'); in that block of pseudocode!  ;-P

-- 
/Daniel P. Brown
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables in forms

2008-06-22 Thread Ron Piggott
I am writing a form right now.  

I would like to make the checkbox an array variable.  The first part of
the array is the component reference, the second part is the package
reference.  What name would you assign to it that I could use in
processing the form in the PHP script this posts to?  

Ron

tr
td valign=topfont face=times new romancenterChildren's 
Activities/center/td
td valign=topfont face=times new romancenterChild's 
ABC's/center/td
tdcenterinput type=checkbox name=component_1_package_1/center/td
tdcenterinput type=checkbox name=component_1_package_2/center/td
/tr


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables

2008-06-19 Thread tedd

At 12:23 AM -0400 6/19/08, Robert Cummings wrote:

?php

$GLOBALS['mysql_host'] = $_REQUEST['host'];

?

I've intentionally used request since I don't know if you would do it
via $_POST or $_GET. Additionally, one would hope you'd
check/filter/process the submitted value before being so careless as to
assign it as I've done above.

Cheers,
Rob.


Rob:

I know you know this, but your method would also include COOKIES, 
which incidentally would take precedence over any same-name-variables 
provided by POST or GET. I believe, GPC is the acronym.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables

2008-06-18 Thread Byron
Hi

I was wondering if this is the correct way to reference a variable from a
file that has been included inside of a function. Also just general
static/global variable usage.

For example:

Myqsql_functions.php

?php
require(config.php)

function ach_mysqlCon()
{
static $con = mysql_connect(global
$mysql_host,$mysql_user,$mysql_pass);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
}

function ach_mysqlCloseCon()
{
if($con)
{
mysql_close($con)
}
}
?


And the variables are defined in config.php

--
config.php
--
?php
//Mysql vars
$mysql_host = localhost;
$mysql_user = [EMAIL PROTECTED];
$mysql_pass = ;
?
--

So my questions are will ach_mysqlCloseCon() recognise the $con variable
in ach_mysqlCon() as it is declared as static? will ach_mysqlCon() recognise
the variables included from config.php as they are declared global? is this
all syntax'd properly?

Also, how would I, for example, change $mysql_host from a form?

Cheers and thanks for any and all assistance.


Re: [PHP] Variables

2008-06-18 Thread Robert Cummings
On Thu, 2008-06-19 at 15:54 +1200, Byron wrote:
 Hi
 
 I was wondering if this is the correct way to reference a variable from a
 file that has been included inside of a function. Also just general
 static/global variable usage.
 
 For example:
 
 Myqsql_functions.php
 
 ?php
 require(config.php)
 
 function ach_mysqlCon()
 {
 static $con = mysql_connect(global
 $mysql_host,$mysql_user,$mysql_pass);
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
 }
 
 function ach_mysqlCloseCon()
 {
 if($con)
 {
 mysql_close($con)
 }
 }
 ?
 
 
 And the variables are defined in config.php
 
 --
 config.php
 --
 ?php
 //Mysql vars
 $mysql_host = localhost;
 $mysql_user = [EMAIL PROTECTED];
 $mysql_pass = ;
 ?
 --
 
 So my questions are will ach_mysqlCloseCon() recognise the $con
 variable
 in ach_mysqlCon() as it is declared as static? will ach_mysqlCon()
 recognise
 the variables included from config.php as they are declared global? is
 this
 all syntax'd properly?

It's all wrong looking :/

Myqsql_functions.php

?php

require(config.php)

function ach_mysqlCon( $init=true )
{
static $con = null;

if( $init  $con === null )
{
$con =
mysql_connect
(
$GLOBALS['mysql_host'],
$GLOBALS['mysql_user'],
$GLOBALS['mysql_pass']
);

if( !$con )
{
die( 'Could not connect: '.mysql_error() );
}
}
}

function ach_mysqlCloseCon()
{
if( ($con = ach_mysqlCon( false )) )
{
mysql_close( $con )
}
}

?


And the variables are defined in config.php

--
config.php
--
?php

//Mysql vars
$GLOBALS['mysql_host'] = localhost;
$GLOBALS['mysql_user'] = [EMAIL PROTECTED];
$GLOBALS['mysql_pass'] = ;

?
--

 Also, how would I, for example, change $mysql_host from a form?
 
 Cheers and thanks for any and all assistance.

You're creating a global database connection... considering you've gone
for static var within the function, you'll only ever create one... so
the host would need to be set before you ever call the connection
function... but to address the question:

?php

$GLOBALS['mysql_host'] = $_REQUEST['host'];

?

I've intentionally used request since I don't know if you would do it
via $_POST or $_GET. Additionally, one would hope you'd
check/filter/process the submitted value before being so careless as to
assign it as I've done above.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variables

2007-08-26 Thread Richard Lynch
On Mon, August 20, 2007 12:41 am, Augusto Morais wrote:
 Hi,


 I want create a variable based in another variable. Example:


 $foo  (a simple variable);

 $myvar_foo


 Does it possible?

variable variables will do it.

But 99.% of the time, you're better off just using an array.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] variables

2007-08-19 Thread Augusto Morais

Hi,


I want create a variable based in another variable. Example:


$foo  (a simple variable);

$myvar_foo


Does it possible?


Thanks


Augusto Morais

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variables

2007-08-19 Thread Micky Hulse

Augusto Morais wrote:

I want create a variable based in another variable. Example:


Maybe this will give you some ideas?:

http://us3.php.net/manual/en/language.variables.variable.php

Good luck!
Cheers,
Micky

--
Wishlists: http://snipurl.com/1gqpj
   Switch: http://browsehappy.com/
 BCC?: http://snipurl.com/w6f8
   My: http://del.icio.us/mhulse

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variables in CSS in PHP question/problems

2007-03-14 Thread Richard Lynch
Surf directly to your CSS URL and see what happens.

There are several possibiliies:
#1.
Your CSS has ?php ... ? in its output, because you have not
convinced your web-server to run your CSS file through PHP to compute
the dynamic result.

You need something like this in .htacces:

File whatever.css
  ForceType application/x-httpd-php
/File


whatever.css should be your CSS filename.

application/x-httpd-php is the default, but your webhost/httpd.conf
could use ANY mime type it felt like using there.  Read your
httpd.conf to figure this out if it's not the usual (above)

Once you get your web-server to pass your CSS through PHP and spit out
the dynamic CSS that you desire...

#2.
Your CSS has what you expect in it, but the browser thinks it's an
HTML document, and shows it as such.

This is because in php.ini your default Content-type is text/html.

But when you spit out your CSS, with the PHP dynamic content to it,
you need this at the very tip-top:

?php
  header(Content-type: text/css);
?

so that the BROWSER knows that you are sending CSS.

Note:
Some browsers may *ignore* the Content-type and assume from the .css
URL that it is CSS.  That's pretty broken, but they are trying to
help the web designers who can't configure their web server to send
the right Content-type for .css files.

#3
Once you have done all that, there is a VERY good chance that your
browser (especially IE) has cached the old .css file...

You may need to hold the control-key and click on the Refresh
button, or hold down SHIFT (or is it ALT?) and control-R for reload
in Mozilla-based, or ...

Actually, if you surf directly to the CSS, and reload that, as in #1
and #2 above, the browser should do the right thing.

But the problem remains that as you change your CSS dynamically, if
the browser is caching the OLD CSS...

So now you may need some no-cache and Last-modified headers as well.

#4
You are on your own to fix the 50-line OOP mess to solve a 1-line
problem... :-)

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variables in CSS in PHP question/problems

2007-03-14 Thread tedd

At 2:15 AM -0500 3/14/07, Richard Lynch wrote:

Surf directly to your CSS URL and see what happens.

There are several possibiliies:
#1.
Your CSS has ?php ... ? in its output, because you have not
convinced your web-server to run your CSS file through PHP to compute
the dynamic result.

You need something like this in .htacces:

File whatever.css
  ForceType application/x-httpd-php
/File

whatever.css should be your CSS filename.



To all:

In addition to what Richard said:

I came into this conversation late, so please forgive me if I'm not 
on track, but if one is trying to use php variables in css, you might 
want to place this at the top of your css files:


?php header('Content-Type: text/css; charset=UTF-8'); ?

and then add this to your .htacces file:

FilesMatch \.(htm|html|css|tpl)$
 SetHandler application/x-httpd-php
/FilesMatch

After that, you can set variables within your css files by ?php 
echo(whatever) ?


hth's

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] variables in CSS in PHP question/problems

2007-03-13 Thread Bruce Gilbert

I stumbled upon this article http://www.chrisjdavis.org/2005/10/16/php-in-css/

and was trying out variables with PGP, but can't get it to work. I
wanted to have a variable image that changes on refresh, and also set
the body color with PHP/CSS and maybe get that to change on refresh
too.

sp from the tutorial mentioned above I have:

[php]
?php
/**
*
* create our font class.
*
**/

class font {

/** CONSTRUCTOR
*
* In PHP 4 your constructor has to have the same name as the class
* in PHP 5 it would be thus:
*
* function __construct($args=array()) {
* $this-fields = array'body','image_float');
*  foreach ($this-fields as $field) {
*   $this-{$field} = $args[$field];
*}
*}
* }
*
**/

function font($args=array()) {
   $this-fields = array('body','image_float');
foreach ($this-fields as $field) {
$this-{$field} = $args[$field];
}
}
}

/**
*
* create our color class.
*
**/

class color {

/**
*
* In PHP 4 your constructor has to have the same name as the class, see above.
*
**/
function color($args=array()) {
   $this-fields = array('body','image_float');
foreach ($this-fields as $field) {
$this-{$field} = $args[$field];
}
}
}

/**
*
* create and setup our color object
*
**/

$color = new color(array(

body = #000,

));

/**
*
* And now we write our rotation script
*
**/

function rotater() {
// we start off with the path to your images directory
$path='images';

// srand(time()) will generates the random number we need for our rotater
srand(time());
   for ($i=0; $i  1; $i++) {

// here we are assigning our random number to a variable name so we
can call it later.  An important note here, you see we are dividing
rand() by 6, 6 is the number of images you have to work with, so if
you have 10, we would: rand()%10)
$random = (rand()%6);

// so our files in our images folder are named side_image1.gif,
side_image2.gif, side_image3.gif etc.  We construct the file name once
we have the random number:
$file = 'image_float';
$image = $path . $file . $random . '.gif';
}

//  echo $image here in the function,
}
?
[/php]

In the XHTML I have:

div class=image_floatnbsp;/div
and of course a body tag.

in my css I have:

div.image_float{
background-image: url(?php rotater(); ?) no-repeat;
float:left;
width:75px;
height:75px;
padding:15px;
}

and also

body
{

background-color: ?php echo $color-body; ?;
}

in my directory, I have a folder called images which is at the root
level with the index file and css, and the images are called
side_image1, side_image2, side_image3 etc.

can anyone see whay this isn't working? Neither the background body
color or the rotating image works.

thanks

--
::Bruce::

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Variables sizes

2006-04-25 Thread Richard Lynch
On Sun, April 23, 2006 10:43 pm, David Killen wrote:
 Is there a maximum size for a variable in PHP. A client of mine is
 having problems working with a file of around 4Mb. Not really being a
 php developer I cannot really answer him. To quote him:

 We are not uploading excel from ftp. We are reading excel file which
 is
 about 4 MB. In php settings maximum size of any variable is set to 2
 MB so
 this setting has to change. As any file reading in a variable will
 only read
 up to 2 MB and then it will stop.

 I wasn't aware of any setting that allows you to change the max
 variable
 size. Can anyone shed any light on this?

As far as I know, there is no limit to the size of a single variable.

The whole script has a limit in php.ini memory_limit

?php phpinfo();? will tell you what that is if you can't read php.ini

If it's not possible to alter memory_limit (on a shared server, for
example) you may have to re-structure the application to read only
PART of the file at a time, and deal with it piece-meal.

This clearly will not work for, say, imagecreatefromjpeg()

But for something like ripping through a CSV file and shoving it into
a database, or reading any kind of text file, really, you can (and
should) do it line by line if it's likely to be a large file.

If you are running PHP from the command line, note that you can
override php.ini or (in more recent versions) override a specific
setting within php.ini directly from the command line.

php -h

on the command line should make the how obvious, and you'll need to
do that to figure out whether you need a whole new php.ini or can
override a single setting anyway.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP Variables sizes

2006-04-25 Thread Nicolas Verhaeghe


Nicolas Verhaeghe - White Echo Technologies
 Is there a maximum size for a variable in PHP. A client of mine is 
 having problems working with a file of around 4Mb. Not really being a 
 php developer I cannot really answer him. To quote him:

 We are not uploading excel from ftp. We are reading excel file which 
 is about 4 MB. In php settings maximum size of any variable is set to 
 2 MB so
 this setting has to change. As any file reading in a variable will
 only read
 up to 2 MB and then it will stop.

 I wasn't aware of any setting that allows you to change the max 
 variable size. Can anyone shed any light on this?

As far as I know, there is no limit to the size of a single variable.

The whole script has a limit in php.ini memory_limit

?php phpinfo();? will tell you what that is if you can't read php.ini

If it's not possible to alter memory_limit (on a shared server, for
example) you may have to re-structure the application to read only PART of
the file at a time, and deal with it piece-meal.

This clearly will not work for, say, imagecreatefromjpeg()

But for something like ripping through a CSV file and shoving it into a
database, or reading any kind of text file, really, you can (and
should) do it line by line if it's likely to be a large file.

If you are running PHP from the command line, note that you can override
php.ini or (in more recent versions) override a specific setting within
php.ini directly from the command line.

php -h

on the command line should make the how obvious, and you'll need to do
that to figure out whether you need a whole new php.ini or can override a
single setting anyway.

--

If the platform is WIMP, I know there is a variable to set somewhere in an
ini in the System32 folder.

Let me know if this is the case, I had this issue in a couple of WAMP
projects.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP Variables sizes

2006-04-23 Thread David Killen
Is there a maximum size for a variable in PHP. A client of mine is
having problems working with a file of around 4Mb. Not really being a
php developer I cannot really answer him. To quote him:

We are not uploading excel from ftp. We are reading excel file which is
about 4 MB. In php settings maximum size of any variable is set to 2 MB so
this setting has to change. As any file reading in a variable will only read
up to 2 MB and then it will stop.

I wasn't aware of any setting that allows you to change the max variable
size. Can anyone shed any light on this?

Cheers,

David.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Variables sizes

2006-04-23 Thread chris smith
On 4/24/06, David Killen [EMAIL PROTECTED] wrote:
 Is there a maximum size for a variable in PHP. A client of mine is
 having problems working with a file of around 4Mb. Not really being a
 php developer I cannot really answer him. To quote him:

 We are not uploading excel from ftp. We are reading excel file which is
 about 4 MB. In php settings maximum size of any variable is set to 2 MB so
 this setting has to change. As any file reading in a variable will only read
 up to 2 MB and then it will stop.

 I wasn't aware of any setting that allows you to change the max variable
 size. Can anyone shed any light on this?

memory_limit will affect this.

http://www.php.net/manual/en/ini.core.php and
http://www.php.net/manual/en/ini.php#ini.list will show you how to
change the limit.

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Parsing PHP variables in XML document

2006-02-27 Thread Ivan Nedialkov


So I have found this code in http://bg.php.net/manual/en/ref.xmlrpc.php
and it evaluates PHP but when I try to use the PIHandler separately. It
doesnt work. So I ask if someone could help me to make parser1 return an
array just like parser2.

PARSER1

?php
$file = xmltest2.xml;

function trustedFile($file)
{
   // only trust local files owned by ourselves
   if (!eregi(^([a-z]+)://, $file)
fileowner($file) == getmyuid()) {
   return true;
   }
   return false;
}

function startElement($parser, $name, $attribs)
{
   echo lt;font color=\#cc\$name/font;
   if (count($attribs)) {
   foreach ($attribs as $k = $v) {
   echo  font color=\#009900\$k/font=\font
   color=\#99\$v/font\;
   }
   }
   echo gt;;
}

function endElement($parser, $name)
{
   echo lt;/font color=\#cc\$name/fontgt;;
}

function characterData($parser, $data)
{
   echo b$data/b;
}

function PIHandler($parser, $target, $data)
{
   switch (strtolower($target)) {
   case php:
   global $parser_file;
   // If the parsed document is trusted, we say it is safe
   // to execute PHP code inside it.  If not, display the code
   // instead.
   if (trustedFile($parser_file[$parser])) {
   eval($data);
   } else {
   printf(Untrusted PHP code: i%s/i,
   htmlspecialchars($data));
   }
   break;
   }
}

function defaultHandler($parser, $data)
{
   if (substr($data, 0, 1) ==   substr($data, -1, 1) == ;) {
   printf('font color=#aa00aa%s/font',
   htmlspecialchars($data));
   } else {
   printf('font size=-1%s/font',
   htmlspecialchars($data));
   }
}

function externalEntityRefHandler($parser, $openEntityNames, $base,
$systemId,
 $publicId) {
   if ($systemId) {
   if (!list($parser, $fp) = new_xml_parser($systemId)) {
   printf(Could not open entity %s at %s\n, $openEntityNames,
   $systemId);
   return false;
   }
   while ($data = fread($fp, 4096)) {
   if (!xml_parse($parser, $data, feof($fp))) {
   printf(XML error: %s at line %d while parsing entity %s
\n,
   xml_error_string(xml_get_error_code($parser)),
   xml_get_current_line_number($parser),
$openEntityNames);
   xml_parser_free($parser);
   return false;
   }
   }
   xml_parser_free($parser);
   return true;
   }
   return false;
}


function new_xml_parser($file)
{
   global $parser_file;

   $xml_parser = xml_parser_create();
   xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
   xml_set_element_handler($xml_parser, startElement, endElement);
   xml_set_character_data_handler($xml_parser, characterData);
   xml_set_processing_instruction_handler($xml_parser, PIHandler);
   xml_set_default_handler($xml_parser, defaultHandler);
   xml_set_external_entity_ref_handler($xml_parser,
externalEntityRefHandler);
  
   if (!($fp = @fopen($file, r))) {
   return false;
   }
   if (!is_array($parser_file)) {
   settype($parser_file, array);
   }
   $parser_file[$xml_parser] = $file;
   return array($xml_parser, $fp);
}

if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
   die(could not open XML input);
}

echo pre;
while ($data = fread($fp, 4096)) {
   if (!xml_parse($xml_parser, $data, feof($fp))) {
   die(sprintf(XML error: %s at line %d\n,
   xml_error_string(xml_get_error_code($xml_parser)),
   xml_get_current_line_number($xml_parser)));
   }
}
echo /pre;
echo parse complete\n;
xml_parser_free($xml_parser);

?

PARSER2


?php
$file = 'data.xml';
$stack = array();

function startTag($parser, $name, $attrs)
{
   global $stack;
   $tag=array(name=$name,attrs=$attrs); 
   array_push($stack,$tag);
 
}

function cdata($parser, $cdata)
{
   global $stack,$i;
  
   if(trim($cdata))
   {   
   $stack[count($stack)-1]['cdata']=$cdata;   
   }
}

function endTag($parser, $name)
{
   global $stack; 
   $stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
   array_pop($stack);
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, startTag, endTag);
xml_set_character_data_handler($xml_parser, cdata);

$data = xml_parse($xml_parser,file_get_contents($file));
if(!$data) {
   die(sprintf(XML error: %s at line %d,
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}

xml_parser_free($xml_parser);

print(pre\n);
print_r($stack);
print(/pre\n);
?



Here is the xml file I used to test:

?xml version=1.0?
!DOCTYPE foo [
!ENTITY testEnt test entity
]
foo
   element attrib=value/
   testEnt;
   ?php echo This is some more PHP code being executed.; ?
/foo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Parsing PHP variables in XML document

2006-02-27 Thread Ivan Nedialkov
I comed up with this

?php
$file = xmltest2.xml;
$stack = array();
$foo3 = wddw;
// start_element_handler ( resource parser, string name, array attribs )
function startElement($parser, $name, $attribs)
{
   global $stack;
   $tag=array(name=$name,attrs=$attrs); 
   array_push($stack,$tag);
}

// end_element_handler ( resource parser, string name )
function endElement($parser, $name)
{
   global $stack; 
   $stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
   array_pop($stack);
}

// handler ( resource parser, string data )
function characterData($parser, $data)
{
   global $stack,$i;
   
   eval(\$data = \$data\;); 

   if(trim($data))
   {  
$stack[count($stack)-1]['data']=$data;   
   }
}

// handler ( resource parser, string target, string data )
function PIHandler($parser, $target, $data)
{
   if ((strtolower($target)) == php) {
global $parser_file;
  eval($data);
   }
}

function defaultHandler($parser, $data)
{

}

function externalEntityRefHandler($parser, $openEntityNames, $base,
$systemId,
 $publicId) {
   if ($systemId) {
   if (!list($parser, $fp) = new_xml_parser($systemId)) {
   printf(Could not open entity %s at %s\n, $openEntityNames,
   $systemId);
   return false;
   }
   while ($data = fread($fp, 4096)) {
   if (!xml_parse($parser, $data, feof($fp))) {
   printf(XML error: %s at line %d while parsing entity %s
\n,
   xml_error_string(xml_get_error_code($parser)),
   xml_get_current_line_number($parser),
$openEntityNames);
   xml_parser_free($parser);
   return false;
   }
   }
   xml_parser_free($parser);
   return true;
   }
   return false;
}



function new_xml_parser($file)
{
   global $parser_file;
$xml_parser = xml_parser_create();
   
   xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
   
   xml_set_processing_instruction_handler($xml_parser, PIHandler);
   
   xml_set_element_handler($xml_parser, startElement, endElement);
   
   xml_set_character_data_handler($xml_parser, characterData); 
   
   xml_set_default_handler($xml_parser, defaultHandler);
   
   xml_set_external_entity_ref_handler($xml_parser,
externalEntityRefHandler);
  
   if (!($fp = @fopen($file, r))) {
   return false;
   }
   if (!is_array($parser_file)) {
   settype($parser_file, array);
   }
   $parser_file[$xml_parser] = $file;
   return array($xml_parser, $fp);
}


if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
   die(could not open XML input);
}

//ERROR
while ($data = fread($fp, 4096)) {
   if (!xml_parse($xml_parser, $data, feof($fp))) {
   die(sprintf(XML error: %s at line %d\n,
   xml_error_string(xml_get_error_code($xml_parser)),
   xml_get_current_line_number($xml_parser)));
   }
}
//END
xml_parser_free($xml_parser);

print(pre\n);
print_r($stack);
print(/pre\n);


?

it evaluates php code. But when I use 

eval(\$data = \$data\;);

the strings in the $data e.g. ('sth $foo other $foo1')do not appear. I
think the problem is that it thinks they are undefined. 

Here is the xml file

?xml version=1.0?
!DOCTYPE foo [
!ENTITY testEnt test entity
]
document
foo
   ?php $foo3='555'; echo Some text;  ?
/foo
foo
hi 
/foo
foofoo $foo3 foo
/foo
/document

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Parsing PHP variables in XML document

2006-02-26 Thread Ivan Nedialkov
Hi,

I have the following problem. I want to import data into my site via PHP
XML Parser, but I also want to include php string variables into
the .xml file and when the xml file is parsed the variables are replaced
whit the corresponding string.

So far all my attempts have been unsuccessful.

Here is the parser i have used

?php


class XMLParser {
   var $filename;
   var $xml;
   var $data;
  
   function XMLParser($xml_file)
   {
   $this-filename = $xml_file;
   $this-xml = xml_parser_create();
   xml_set_object($this-xml, $this);
   xml_set_element_handler($this-xml, 'startHandler',
'endHandler');
   xml_set_character_data_handler($this-xml, 'dataHandler');
   $this-parse($xml_file);
   }
  
   function parse($xml_file)
   {
   if (!($fp = fopen($xml_file, 'r'))) {
 die('Cannot open XML data file: '.$xml_file);
   return false;
   }

   $bytes_to_parse = 512;

   while ($data = fread($fp, $bytes_to_parse)) {
   $parse = xml_parse($this-xml, $data, feof($fp));
  
   if (!$parse) {
   die(sprintf(XML error: %s at line %d,
   xml_error_string(xml_get_error_code($this-xml)),
   xml_get_current_line_number($this-xml)));
   xml_parser_free($this-xml
 );
   }
   }

   return true;
   }
  
   function startHandler($parser, $name, $attributes)
   {
   $data['name'] = $name;
   if ($attributes) { $data['attributes'] = $attributes; }
   $this-data[] = $data;
   }

   function dataHandler($parser, $data)
   {
   if ($data = trim($data)) {
   $index = count($this-data) - 1;
   // begin multi-line bug fix (use the .= operator)
   $this-data[$index]['content'] .= $data;
   // end multi-line bug fix
   }
   }

   function endHandler($parser, $name)
   {
   if (count($this-data)  1) {
   $data = array_pop($this-data);
   $index = count($this-data) - 1;
   $this-data[$index]['child'][] = $data;
   }
   }
}



$url = 'data.xml';
$myFile = new XMLParser($url);

echo PRE;
print_r($myFile-data);
echo /PRE;

$foo3 = foo3;
?

here is a sample XML file

?xml version='1.0'?
!DOCTYPE chapter SYSTEM /just/a/test.dtd [
!ENTITY plainEntity FOO entity
!ENTITY systemEntity SYSTEM xmltest2.xml
]
document

data
foo1
/data
data
foo2
/data
data
?php echo $foo3; ?
/data
data
foo4
/data
data
foo5
/data
/document

and what I get is:

Array
(
[0] = Array
(
[name] = DOCUMENT
[child] = Array
(
[0] = Array
(
[name] = DATA
[content] = foo1
)

[1] = Array
(
[name] = DATA
[content] = foo2
)

[2] = Array
(
[name] = DATA
)

[3] = Array
(
[name] = DATA
[content] = foo4
)

[4] = Array
(
[name] = DATA
[content] = foo5
)

)

)

)

So I want $myFile-data[0][child][2][content] to be equal to $foo3



   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Bogdan Ribic

Hi Ivan,

  You might be able to use output buffering in conjunction with 
including your xml file. Something like:


ob_start();
include $xml_file;
$content = ob_end_flush();

  and then parse the $content string. If you are doing this from within 
a function and you want access to global variables, you should import 
all global variables first, via extract($GLOBALS);


  Btw, this is just an idea, and untested - use at your own risk :)

Boban.


Ivan Nedialkov wrote:

Hi,

I have the following problem. I want to import data into my site via PHP
XML Parser, but I also want to include php string variables into
the .xml file and when the xml file is parsed the variables are replaced
whit the corresponding string.

So far all my attempts have been unsuccessful.

Here is the parser i have used

?php


class XMLParser {
   var $filename;
   var $xml;
   var $data;
  
   function XMLParser($xml_file)

   {
   $this-filename = $xml_file;
   $this-xml = xml_parser_create();
   xml_set_object($this-xml, $this);
   xml_set_element_handler($this-xml, 'startHandler',
'endHandler');
   xml_set_character_data_handler($this-xml, 'dataHandler');
   $this-parse($xml_file);
   }
  
   function parse($xml_file)

   {
   if (!($fp = fopen($xml_file, 'r'))) {
 die('Cannot open XML data file: '.$xml_file);
   return false;
   }

   $bytes_to_parse = 512;

   while ($data = fread($fp, $bytes_to_parse)) {
   $parse = xml_parse($this-xml, $data, feof($fp));
  
   if (!$parse) {

   die(sprintf(XML error: %s at line %d,
   xml_error_string(xml_get_error_code($this-xml)),
   xml_get_current_line_number($this-xml)));
   xml_parser_free($this-xml
 );
   }
   }

   return true;
   }
  
   function startHandler($parser, $name, $attributes)

   {
   $data['name'] = $name;
   if ($attributes) { $data['attributes'] = $attributes; }
   $this-data[] = $data;
   }

   function dataHandler($parser, $data)
   {
   if ($data = trim($data)) {
   $index = count($this-data) - 1;
   // begin multi-line bug fix (use the .= operator)
   $this-data[$index]['content'] .= $data;
   // end multi-line bug fix
   }
   }

   function endHandler($parser, $name)
   {
   if (count($this-data)  1) {
   $data = array_pop($this-data);
   $index = count($this-data) - 1;
   $this-data[$index]['child'][] = $data;
   }
   }
}



$url = 'data.xml';
$myFile = new XMLParser($url);

echo PRE;
print_r($myFile-data);
echo /PRE;

$foo3 = foo3;
?

here is a sample XML file

?xml version='1.0'?
!DOCTYPE chapter SYSTEM /just/a/test.dtd [
!ENTITY plainEntity FOO entity
!ENTITY systemEntity SYSTEM xmltest2.xml
]
document

data
foo1
/data
data
foo2
/data
data
?php echo $foo3; ?
/data
data
foo4
/data
data
foo5
/data
/document

and what I get is:

Array
(
[0] = Array
(
[name] = DOCUMENT
[child] = Array
(
[0] = Array
(
[name] = DATA
[content] = foo1
)

[1] = Array
(
[name] = DATA
[content] = foo2
)

[2] = Array
(
[name] = DATA
)

[3] = Array
(
[name] = DATA
[content] = foo4
)

[4] = Array
(
[name] = DATA
[content] = foo5
)

)

)

)

So I want $myFile-data[0][child][2][content] to be equal to $foo3



   



--

   Open source PHP code generator for DB operations
   http://sourceforge.net/projects/bfrcg/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Bogdan Ribic
Hmmm, come to think of it, it would only work if short_open_tags ini 
directive is turned OFF, which in most cases it won't be :(


Bogdan Ribic wrote:

Hi Ivan,

  You might be able to use output buffering in conjunction with 
including your xml file. Something like:


ob_start();
include $xml_file;
$content = ob_end_flush();

  and then parse the $content string. If you are doing this from within 
a function and you want access to global variables, you should import 
all global variables first, via extract($GLOBALS);


  Btw, this is just an idea, and untested - use at your own risk :)

Boban.





--

   Open source PHP code generator for DB operations
   http://sourceforge.net/projects/bfrcg/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread chris smith
On 2/26/06, Bogdan Ribic [EMAIL PROTECTED] wrote:
 Hmmm, come to think of it, it would only work if short_open_tags ini
 directive is turned OFF, which in most cases it won't be :(

You can turn it off with a htaccess file.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Ivan Nedialkov
Well isn't there a way instead of using only variables, to use sth like
?php echo $foo; ?
I tried it but it doesnt work
The parser returns blank! 

On Sun, 2006-02-26 at 12:02 +0100, Bogdan Ribic wrote:
 Hmmm, come to think of it, it would only work if short_open_tags ini 
 directive is turned OFF, which in most cases it won't be :(
 
 Bogdan Ribic wrote:
  Hi Ivan,
  
You might be able to use output buffering in conjunction with 
  including your xml file. Something like:
  
  ob_start();
  include $xml_file;
  $content = ob_end_flush();
  
and then parse the $content string. If you are doing this from within 
  a function and you want access to global variables, you should import 
  all global variables first, via extract($GLOBALS);
  
Btw, this is just an idea, and untested - use at your own risk :)
  
  Boban.
 
 
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Parsing PHP variables in XML document

2006-02-26 Thread Bogdan Ribic

Ivan,

Did you try entering the code with debugger, or at least printing out 
what output buffer was holding, ie $content var in my example? Can you 
post exact code? Also, is short_tags turned on or off in php.ini? If it 
is on, php will get confused on first line of your xml file, it will 
think that ?xml is a php openning tag.


In your original code you were calling the parser that was expecting 
$foo3 to be set, but you were setting the $foo3 *after* parsing, are you 
sure you're not making a mistake like that again?


Ivan Nedialkov wrote:

Well isn't there a way instead of using only variables, to use sth like
?php echo $foo; ?
I tried it but it doesnt work
The parser returns blank! 


--

   Open source PHP code generator for DB operations
   http://sourceforge.net/projects/bfrcg/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variables in PHP

2006-02-03 Thread Richard Lynch


Source code.

On Fri, February 3, 2006 12:43 am, suresh kumar wrote:
 hi,
In my project i assigned name of the text field as
 'loginform'.but i got error msg like 'Undefined
 variable'
 then i changed the name as 'hiddenfield' but same
 error.any one having idea reply me.


   A.suresh



 __
 Yahoo! India Matrimony: Find your partner now. Go to
 http://yahoo.shaadi.com

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] variables in PHP

2006-02-02 Thread suresh kumar
hi,
   In my project i assigned name of the text field as 
'loginform'.but i got error msg like 'Undefined
variable'
then i changed the name as 'hiddenfield' but same
error.any one having idea reply me.


  A.suresh



__ 
Yahoo! India Matrimony: Find your partner now. Go to http://yahoo.shaadi.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] variables in PHP

2006-02-02 Thread Angelo Zanetti


suresh kumar wrote:

hi,
   In my project i assigned name of the text field as 
'loginform'.but i got error msg like 'Undefined

variable'
then i changed the name as 'hiddenfield' but same
error.any one having idea reply me.



POST the code so we can see exactly whats going on...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Which is faster, a MySQL access, or a set of PHP variables?

2006-01-02 Thread Dave M G

Thank you for the advice.
The point was raised, and it's a good one, that if I'm getting content
from the database for most pages, then attaining the necessary
translations probably won't make a difference.
And of course, it is true that at my current levels of hits, the server
load is negligible. But, of course, one always hopes that site
popularity will increase and justify the efforts of making it efficient.
I think I am going to database the translations for now, and then later
if need be, I will go with the suggestions of creating a list of
variables from the database once a day with a cron job.

I appreciate all the help people have given to let me understand the
issue.

--
Dave M G

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables and Strings

2005-12-30 Thread Jochem Maas

Jim Moseby wrote:
Thanks for the responses guys, but what i'm saying is i would 


...



I believe what Jochem is trying to tell you is that when you assign the
string variable, the variable names are expanded to their values, so the
names are no longer available.


exactly - nicely put Jim.



Consider this:

$partname='widget';
$amount=100;

$string=This $partname costs $amount dollars;

/*
$string now equals This widget costs 100 dollars, so when you pass it to
your function, it has no way to know for sure what the variables were, or
that there even were ANY variables involved in the generation of the string.

The variable NAMES are not passed because PHP expands them to their values
and sets $string accordingly.
*/

$string='This $partname costs $amount dollars';

$string now equals This $partname costs $amount dollars.  In this case, I
used single quotes.  The values are not expanded and the variable NAMES are
passed.  The VALUE of the variables are not.  So you could then have a
function look for any word that starts with a $ and return an array of
names.


hopefully thats clear to the OP now - and he can [re]state his goal in
order that we might point him into a more fruitful direction!



That all being said, what in the world are you trying to do with this?  I
bet you $1.78 (the change in my desk drawer) there is a much better way to
solve whatever problem it is than the way you are trying here.


yeah 'Superman' explain what it is you want to do AND why - then maybe we can
give you some help - what you are currently asking is impossible (well actually
Jay Blanchard hinted at a way to do it but I firmly believe that its 
conceptually
over your head atm and very probably not a good solution to what you want to 
acheive -
which is not to say that Jays hint was crap or wrong; more like the problem you
posed originally is moot.)



JM

Because it ruins the flow of the conversation.


evil genius ;-)




Why is top posting a bad thing?





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Which is faster, a MySQL access, or a set of PHP variables?

2005-12-30 Thread Dave M G
PHP General,

I have a site where I will set the interface up to be multilingual.
This means that all the snippets of text which make up the menu and
other elements of navigation common to most pages will be stored as
variables.

In most web site set ups that I have seen, especially on forums, the
text is stored in a PHP script which is just a long list of variables.

I wondered if there was any downside to storing the list of interface
texts in a MySQL database, then calling them as an array when the page
loads?

This would have one minor advantage, which is that as I expand to new
languages, I could build a simple web interface where people could input
new languages into a form.

However, is it a drag on a server to have to reach into the MySQL
database to retrieve the array of texts each time the page loads? Note
that the texts will be something like 20 to 30 small one to four word
phrases like contact and previous page and that sort of thing.

On the surface, it doesn't seem like this would be much different than
accessing a PHP script with a list of variables. But then, I figured
there might be a reason why I've never seen it done this way.

Opinions would be much appreciated.

--
Dave M G

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Variables and Strings

2005-12-30 Thread Jay Blanchard
[snip]
yeah 'Superman' explain what it is you want to do AND why - then maybe we
can
give you some help - what you are currently asking is impossible (well
actually
Jay Blanchard hinted at a way to do it but I firmly believe that its
conceptually
over your head atm and very probably not a good solution to what you want to
acheive -
which is not to say that Jays hint was crap or wrong; more like the problem
you
posed originally is moot.)
[/snip]

We actually wrote a little code doohickey called Variable Hunter in which
the doohickey could be run within a project folder and locate all of the
variables with their respective name spaces and lines numbers. Nifty little
tool.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Which is faster, a MySQL access, or a set of PHP variables?

2005-12-30 Thread Jochem Maas

Dave M G wrote:

PHP General,

I have a site where I will set the interface up to be multilingual.
This means that all the snippets of text which make up the menu and
other elements of navigation common to most pages will be stored as
variables.

In most web site set ups that I have seen, especially on forums, the
text is stored in a PHP script which is just a long list of variables.

I wondered if there was any downside to storing the list of interface
texts in a MySQL database, then calling them as an array when the page
loads?

This would have one minor advantage, which is that as I expand to new
languages, I could build a simple web interface where people could input
new languages into a form.


true - rather than trying to writing an interface thats _properly_ capable
tf editing phpb-like language files - which although not impossible is a lot
more difficult to make fool-proof than one first imagines (I have very
ingenious 'fools' who want to edit stuff like that!)



However, is it a drag on a server to have to reach into the MySQL
database to retrieve the array of texts each time the page loads? Note
that the texts will be something like 20 to 30 small one to four word
phrases like contact and previous page and that sort of thing.


using var_export() you can write the array to a file on a TMPFS filesystem
(e.g. /dev/shm) as a cache and have a cmdline script or something that you run
whenever you want the lang itmes to be updated - reading a single small file in 
off
disk (which in the case of TMPFS is in RAM - bonus!!!) will be faster in general
than querying MySQL and building the array.

essentially this gives you the best of both world - with the added bonus of
begin able to easily control publication of updates to the lang items.



On the surface, it doesn't seem like this would be much different than
accessing a PHP script with a list of variables. But then, I figured
there might be a reason why I've never seen it done this way.


basically unless you have some killer site thats taking a beating and
needs to take performance very seriously in order to stay in the air then either
way will do fine. a DB call on every request is somewhat wasteful but a low 
traffic
site won't mind one little bit.



Opinions would be much appreciated.

--
Dave M G



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables and Strings

2005-12-30 Thread Jochem Maas

Jay Blanchard wrote:

[snip]
yeah 'Superman' explain what it is you want to do AND why - then maybe we
can
give you some help - what you are currently asking is impossible (well
actually
Jay Blanchard hinted at a way to do it but I firmly believe that its
conceptually
over your head atm and very probably not a good solution to what you want to
acheive -
which is not to say that Jays hint was crap or wrong; more like the problem
you
posed originally is moot.)
[/snip]

We actually wrote a little code doohickey called Variable Hunter in which
the doohickey could be run within a project folder and locate all of the
variables with their respective name spaces and lines numbers. Nifty little
tool.


ah heck is that the same code that _we_ (Jay and me, etc) played with to find 
SQL queries?
or something that was based on it?
I remember Robin Vickery coming up with a token based variant which was rather 
nifty -
must look into that agian sometime!

rgds,
JOchem





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Variables and Strings

2005-12-30 Thread Jay Blanchard
[snip]
ah heck is that the same code that _we_ (Jay and me, etc) played with to
find SQL queries?
or something that was based on it?
I remember Robin Vickery coming up with a token based variant which was
rather nifty -
must look into that agian sometime!
[/snip]

They are all variants of that. All nifty little tools. We should gather
those up someplace...shouldn't we?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables and Strings

2005-12-30 Thread John Nichel

Jay Blanchard wrote:

[snip]
yeah 'Superman' explain what it is you want to do AND why - then maybe we
can
give you some help - what you are currently asking is impossible (well
actually
Jay Blanchard hinted at a way to do it but I firmly believe that its
conceptually
over your head atm and very probably not a good solution to what you want to
acheive -
which is not to say that Jays hint was crap or wrong; more like the problem
you
posed originally is moot.)
[/snip]

We actually wrote a little code doohickey called Variable Hunter in which
the doohickey could be run within a project folder and locate all of the
variables with their respective name spaces and lines numbers. Nifty little
tool.



I wrote a doohickey once which searched for all variable searching 
doohickies.


--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Variables and Strings

2005-12-30 Thread Jay Blanchard
[snip]
I wrote a doohickey once which searched for all variable searching
doohickies.
[/snip]

I cannot tell you how happy I am to see you use the past perfect tense
correctly there.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Which is faster, a MySQL access, or a set of PHP variables?

2005-12-30 Thread Miles Thompson

At 10:32 AM 12/30/2005, Dave M G wrote:


PHP General,

I have a site where I will set the interface up to be multilingual.
This means that all the snippets of text which make up the menu and
other elements of navigation common to most pages will be stored as
variables.

In most web site set ups that I have seen, especially on forums, the
text is stored in a PHP script which is just a long list of variables.

I wondered if there was any downside to storing the list of interface
texts in a MySQL database, then calling them as an array when the page
loads?

This would have one minor advantage, which is that as I expand to new
languages, I could build a simple web interface where people could input
new languages into a form.

However, is it a drag on a server to have to reach into the MySQL
database to retrieve the array of texts each time the page loads? Note
that the texts will be something like 20 to 30 small one to four word
phrases like contact and previous page and that sort of thing.

On the surface, it doesn't seem like this would be much different 
than

accessing a PHP script with a list of variables. But then, I figured
there might be a reason why I've never seen it done this way.

Opinions would be much appreciated.

--
Dave M G


Dave,

I did that for an online auction site, now defunct, where the languages 
could be German or English. To expand to Spanish one had only to supply the 
structure and have someone who knew one of the other languages to enter the 
correct terms. That would be pasted into the script and run, presto, the 
site was available in Spanish.


Database hits ere not a problem, as all of the content on the page came 
from a database, none of the content was static.


That was three years ago, and it was done that way because native language 
support was wobbly in both PHP and Apache.


Joachem's solution is probably better for today.

Cheers - Miles Thompson 



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.371 / Virus Database: 267.14.9/216 - Release Date: 12/29/2005

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables and Strings

2005-12-30 Thread John Nichel

Jay Blanchard wrote:

[snip]
ah heck is that the same code that _we_ (Jay and me, etc) played with to
find SQL queries?
or something that was based on it?
I remember Robin Vickery coming up with a token based variant which was
rather nifty -
must look into that agian sometime!
[/snip]

They are all variants of that. All nifty little tools. We should gather
those up someplace...shouldn't we?



Well, I just purchased some domains for that.  Who wants to develop it?  ;)

phpdepository.com
phpdepository.org
phpdepository.net

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Variables and Strings

2005-12-30 Thread Jay Blanchard
[snip]
 They are all variants of that. All nifty little tools. We should gather
 those up someplace...shouldn't we?
 

Well, I just purchased some domains for that.  Who wants to develop it?  ;)

phpdepository.com
phpdepository.org
phpdepository.net
[/snip]

I'll contribute...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Which is faster, a MySQL access, or a set of PHP variables?

2005-12-30 Thread Richard Lynch
On Fri, December 30, 2005 8:32 am, Dave M G wrote:
   I wondered if there was any downside to storing the list of interface
 texts in a MySQL database, then calling them as an array when the page
 loads?

If you are already connecting to the database, then you are comparing
an extra query or two to loading a file from the hard drive and the
database wins on performance.

Unless you are already loading some file where it would be convenient
to stick the text, and then the variables win.

Actually, this all depends on your hardware and database/drive
performance setup...

There really is NOT a good answer to this question from a
performance stand-point.

But then it's not a good question, really, unless you REALLY expect
your site to get a ton of traffic, because the performance of the
machine will probably not be a big factor in your success, compared to
maintainability of code, feature-set of the site, cool-ness and
prettiness and marketing and...  All of those will matter more to your
success than raw performance.

   This would have one minor advantage, which is that as I expand to new
 languages, I could build a simple web interface where people could
 input
 new languages into a form.

Something to consider:

Can you get data in other character sets into and out of your database
and web application?

If you plan to support 2-byte (or more) character sets, this is not
trivial at all -- or maybe it is, but you have to at least plan ahead
for it from the get-go.

   However, is it a drag on a server to have to reach into the MySQL
 database to retrieve the array of texts each time the page loads? Note
 that the texts will be something like 20 to 30 small one to four word
 phrases like contact and previous page and that sort of thing.

   On the surface, it doesn't seem like this would be much different
 than
 accessing a PHP script with a list of variables. But then, I figured
 there might be a reason why I've never seen it done this way.

Generally, on most projects, the people who are contributing the
translations of internal things like contact and previous page are
developers who are comfy with editing a text file, and putting them in
as text files with, say CVS or subversion, gives the developers
control over versioning etc.

That's not to say you COULDN'T do something similar with the database,
or run hourly dumps of (some) tables into CVS or something.

I don't think it's going to matter much which way you do this, so long
as you can plan ahead for all the character-encodings you will ever
need, and make sure you can handle them all.

Perhaps try it with a test phrase like Hello which you can probably
find in every language fairly easily.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables and Strings

2005-12-30 Thread Richard Lynch
On Thu, December 29, 2005 3:31 pm, PHP Superman wrote:
 Thanks for the responses guys, but what i'm saying is i would like to
 return
 all the variable names i have in a string,
 $String=Blah Blah Blah $VarName Blah Blah Blah;

$VarName = 'xyz';
$String now has Blah Blah Blah xyz Blah Blah Blah in it.

There is *NOTHING* left to indicate that xyz came from a variable.

You simply do not have the context available to do what you want.

Now, you *COULD* do like this:

$VarName = 'xyz';
$Template = 'Blah Blah Blah $VarName Blah Blah Blah';

Note the use of single quotes that does NOT interpret variables.

You now have a $Template from which, with luck, you could:
A) compose $String using:
eval('$String = $Template;');

B) use something not unlike this:
preg_match_all('/\\$([a-z0-9_]+/sU', $Template, $variables);
foreach($variables[1] as $varname){
  echo $varname = , $$varname;
}

I'll warn you right now that whatever it is you are doing, there is
PROBABLY a better easier way to do it, but you've put on blinders to
other solutions and only asked us how to do what you think you want to
do, which is probably not what you really want to do...

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables and Strings

2005-12-29 Thread Jochem Maas

PHP Superman wrote:

Hey everyone, is there a way to return all the variables from a string into
an array, for example
$Var1=Yo;
$Var2=Man;
$SQL=SELECT * FROM tblname WHERE 4=$Var1 AND WHERE 3=$Var2;
$AllVars=MySpecialFunction($SQL);


your function MySpecialFunction() will recieve the following string:

SELECT * FROM tblname WHERE 4=Yo AND WHERE 3=Man

which apart from being (probably) incorrect SQL, is just a string -
how is your special function supposed to tell which chars are part of
the previously injected variables' values - and even more impossible:
how would the function find out what those variables we're called to
begin with (it can't).

what is it you would like to achieve?

rgds,
jochem

PS - learn to walk before you fly ;-)


print_r($AllVars);

would ideally print an array like:
{
array
$Var1=Yo
$Var2=Man

}
i think i should use an ereg or preg replace but I don't know much about
them or how to use them, thanks in advance



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables and Strings

2005-12-29 Thread PHP Superman
Thanks for the responses guys, but what i'm saying is i would like to return
all the variable names i have in a string,
$String=Blah Blah Blah $VarName Blah Blah Blah;
$Vars=myspecialfunction($Varname);
echo ($Vars);

that code would produce $Varname, if there were more variables it would also
return the Variable Names in an array
On 12/29/05, Jochem Maas [EMAIL PROTECTED] wrote:

 PHP Superman wrote:
  Hey everyone, is there a way to return all the variables from a string
 into
  an array, for example
  $Var1=Yo;
  $Var2=Man;
  $SQL=SELECT * FROM tblname WHERE 4=$Var1 AND WHERE 3=$Var2;
  $AllVars=MySpecialFunction($SQL);

 your function MySpecialFunction() will recieve the following string:

 SELECT * FROM tblname WHERE 4=Yo AND WHERE 3=Man

 which apart from being (probably) incorrect SQL, is just a string -
 how is your special function supposed to tell which chars are part of
 the previously injected variables' values - and even more impossible:
 how would the function find out what those variables we're called to
 begin with (it can't).

 what is it you would like to achieve?

 rgds,
 jochem

 PS - learn to walk before you fly ;-)

  print_r($AllVars);
 
  would ideally print an array like:
  {
  array
  $Var1=Yo
  $Var2=Man
 
  }
  i think i should use an ereg or preg replace but I don't know much about
  them or how to use them, thanks in advance
 




--
Hi Everyone, I am running PHP 5 on Windosws XP SP2 with MySQL5, Bye Now!


RE: [PHP] Variables and Strings

2005-12-29 Thread Jay Blanchard
[snip]
Thanks for the responses guys, but what i'm saying is i would like to return
all the variable names i have in a string,
$String=Blah Blah Blah $VarName Blah Blah Blah;
$Vars=myspecialfunction($Varname);
echo ($Vars);

that code would produce $Varname, if there were more variables it would also
return the Variable Names in an array
[/snip]

And you call yourself Superman?!? 

Keep in mind that the variable name in a double quoted string is
interpreted, you would have to use an outside process to read each line of
the file, locate the lines where the variables are, and then process to your
liking.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Variables and Strings

2005-12-29 Thread Jim Moseby
 
 Thanks for the responses guys, but what i'm saying is i would 
 like to return
 all the variable names i have in a string,
 $String=Blah Blah Blah $VarName Blah Blah Blah;
 $Vars=myspecialfunction($Varname);
 echo ($Vars);
 
 that code would produce $Varname, if there were more 
 variables it would also
 return the Variable Names in an array

I believe what Jochem is trying to tell you is that when you assign the
string variable, the variable names are expanded to their values, so the
names are no longer available.

Consider this:

$partname='widget';
$amount=100;

$string=This $partname costs $amount dollars;

/*
$string now equals This widget costs 100 dollars, so when you pass it to
your function, it has no way to know for sure what the variables were, or
that there even were ANY variables involved in the generation of the string.

The variable NAMES are not passed because PHP expands them to their values
and sets $string accordingly.
*/

$string='This $partname costs $amount dollars';

$string now equals This $partname costs $amount dollars.  In this case, I
used single quotes.  The values are not expanded and the variable NAMES are
passed.  The VALUE of the variables are not.  So you could then have a
function look for any word that starts with a $ and return an array of
names.

That all being said, what in the world are you trying to do with this?  I
bet you $1.78 (the change in my desk drawer) there is a much better way to
solve whatever problem it is than the way you are trying here.

JM

Because it ruins the flow of the conversation.
Why is top posting a bad thing?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables and Strings

2005-12-28 Thread PHP Superman
Hey everyone, is there a way to return all the variables from a string into
an array, for example
$Var1=Yo;
$Var2=Man;
$SQL=SELECT * FROM tblname WHERE 4=$Var1 AND WHERE 3=$Var2;
$AllVars=MySpecialFunction($SQL);
print_r($AllVars);

would ideally print an array like:
{
array
$Var1=Yo
$Var2=Man

}
i think i should use an ereg or preg replace but I don't know much about
them or how to use them, thanks in advance


Re: [PHP] Variables and Strings

2005-12-28 Thread Curt Zirzow
On Wed, Dec 28, 2005 at 10:30:04PM -0500, PHP Superman wrote:
 Hey everyone, is there a way to return all the variables from a string into
 an array, for example
 $Var1=Yo;
 $Var2=Man;
 $SQL=SELECT * FROM tblname WHERE 4=$Var1 AND WHERE 3=$Var2;
 $AllVars=MySpecialFunction($SQL);
 print_r($AllVars);

I'm not sure what your trying to do but well,

var_dump($Var1, $Var2, $AllVars);

Curt.
-- 
cat .signature: No such file or directory

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables in Variables?

2005-11-18 Thread Marquez Design
Greetings.

Does anyone know how to do this?

I have,

$var

$var2

In a field called two_vars in a MySQL db.

I am calling the variables inside PHP document.

In that document I am saying:

$var = time
$var2 = clock

!-- I do the query in MySQL here --

echo $two_vars;

But the what prints out is

$var 

$var2 

not time and clock.  I know that is what is in the database, but I want
it to replace the variables when printed in the PHP file.

Does this make sense to anyone? Does anyone know how to do this?

--
Steve

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables in variables?

2005-11-18 Thread Marquez Design
This is a little more specific:

I have a template in the database which looks something like this:

html
title$page_title/title

body

Image: $image p /
img src = \$image\

Main Text: $mtext br /
Text2: $text2 br /
Text3: $text3 br /

/body
html

The variable name is $somecontent

When I call $somecontent in the PHP file, it displays exactly like it is
above. It does not replace the variables.

Is there a reason for this?

Here is my PHP file:



?php

include cnx.php;
include includes/header.php;

//Include the content
$select_data = SELECT * FROM template WHERE tmpl_name = \my_template\;;
$response = mysql_query( $select_data, $cnx );

//now print it out for the user.
if ( $one_line_of_data = mysql_fetch_array( $response ) ) {
extract ( $one_line_of_data );
}

$file = $_POST['file'];
$page_title   = $_POST['page_title'];
$image   = $_POST['image'];
$mtext   = $_POST['mtext'];
$text2   = $_POST['text2'];
$text3   = $_POST['text3'];

if (file_exists($dir . $file)) {
   echo centerp /p class=\NormalBold\Success!p /p /;
} else {
   echo The file $file does not exist;
}

$filename = $file;

//Update the table in MySQL
$update_data = UPDATE cms_pages SET page_title = '$page_title', image =
'$image', mtext = '$mtext', text2 = '$text2', text3 = '$text2' WHERE
filename = '$file';
$response = mysql_query( $update_data, $cnx );
if(mysql_error()) die ('database errorbr'. mysql_error());

//Begining of Template Construction

  $mtext = nl2br($mtext);
  $text2 = nl2br($text2);
  $text3 = nl2br($text3);
  
//include content.php; This works with an external page included, but I
would like it to be in the database for easy changes.

// Is the file writable?
if (is_writable($dir. $filename)) {


   if (!$handle = fopen($dir . $filename, 'w')) {
 echo Cannot open file ($filename);
 exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
   echo Cannot write to file ($filename);
   exit;
   }
  
   echo centerp /p class=\NormalText\$filename has been
updated./pp //center;
  
   fclose($handle);

} else {
   echo The file $filename is not writable;
}

include includes/footer.php;

? 
/html






on 11/18/05 7:14 PM Lists ([EMAIL PROTECTED]) wrote:

 ?
 $var = time;
 $var2 = clock;
 echo $var$var2;
 //outputs timeclock
 
 $two_vars = $var$var2;
 echo $two_vars;
 //outputs timeclock
 ?
 
 Why put two variables in one field?  But if you want to store them,
 do: $var, $var2.  After pulling this back from the database,
 explode into an array at the comma, using list to call them var and
 var2.
 
 On Nov 18, 2005, at 7:54 PM, Marquez Design wrote:
 
 Greetings.
 
 Does anyone know how to do this?
 
 I have,
 
 $var
 
 $var2
 
 In a field called two_vars in a MySQL db.
 
 I am calling the variables inside PHP document.
 
 In that document I am saying:
 
 $var = time
 $var2 = clock
 
 !-- I do the query in MySQL here --
 
 echo $two_vars;
 
 But the what prints out is
 
 $var
 
 $var2
 
 not time and clock.  I know that is what is in the database,
 but I want
 it to replace the variables when printed in the PHP file.
 
 Does this make sense to anyone? Does anyone know how to do this?
 
 --
 Steve
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables not available

2005-09-12 Thread Dotan Cohen
I am running php 5.0.4 at home on my Fedora Core 4 box. Post and get
variables are not available in my scripts. For instance, in
file.php?foo=bar the variable $foo is empty. Same thing for variables
passed in forms (get or post), which is how I came across this.

What could cause this? How could I repair it? Thanks.

Dotan Cohen
http://lyricslist.com/lyrics/artist_albums/458/spice_girls.php
Spice Girls Song Lyrics

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables not available

2005-09-12 Thread Burhan Khalid

Dotan Cohen wrote:

I am running php 5.0.4 at home on my Fedora Core 4 box. Post and get
variables are not available in my scripts. For instance, in
file.php?foo=bar the variable $foo is empty. Same thing for variables
passed in forms (get or post), which is how I came across this.

What could cause this? How could I repair it? Thanks.


This is not a 'problem'.

See http://www.php.net/manual/en/security.globals.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables not available

2005-09-12 Thread Dotan Cohen
On 9/12/05, Burhan Khalid [EMAIL PROTECTED] wrote:
 Dotan Cohen wrote:
  I am running php 5.0.4 at home on my Fedora Core 4 box. Post and get
  variables are not available in my scripts. For instance, in
  file.php?foo=bar the variable $foo is empty. Same thing for variables
  passed in forms (get or post), which is how I came across this.
 
  What could cause this? How could I repair it? Thanks.
 
 This is not a 'problem'.
 
 See http://www.php.net/manual/en/security.globals.php
 

Thanks. I should have known that, I guess.

Dotan
http://lyricslist.com/lyrics/artist_albums/127/cooper_alice.php
Cooper, Alice Song Lyrics

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables not available

2005-09-12 Thread Ryan A

On 9/12/2005 9:00:46 AM, Dotan Cohen ([EMAIL PROTECTED]) wrote:
 I am running php 5.0.4 at home on my Fedora Core 4 box. Post and get
 variables are not available in my scripts. For instance, in
 file.php?foo=bar the variable $foo is empty. Same thing for variables
 passed in forms (get or post), which is how I came across this.
 
 What could cause this? How could I repair it? Thanks.


Have you checked your register_globals?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables not available

2005-09-12 Thread Dotan Cohen
On 9/12/05, Ryan A [EMAIL PROTECTED] wrote:
 
 On 9/12/2005 9:00:46 AM, Dotan Cohen ([EMAIL PROTECTED]) wrote:
  I am running php 5.0.4 at home on my Fedora Core 4 box. Post and get
  variables are not available in my scripts. For instance, in
  file.php?foo=bar the variable $foo is empty. Same thing for variables
  passed in forms (get or post), which is how I came across this.
 
  What could cause this? How could I repair it? Thanks.
 
 
 Have you checked your register_globals?
 

The 'problem' was in fact register globals. I did a little research
and decided to leave it off. So I'm accessing the variables like
$_POST['foo']. Thanks.

Dotan
http://lyricslist.com/lyrics/artist_albums/332/mccartney_paul.php
McCartney, Paul Song Lyrics

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to read PHP variables.

2005-07-15 Thread Bruno B B Magalhães

Hi everybody,

well I don´t want to include and use those variables or  set then. I  
want to read the file, parse the vars to a form, so the user can  
change the system configs using the web instead of FTP...


I am thinking reading using a simple include, and then clean the file  
contents and write the strings..


Best Regards,
Bruno B B Magalhães

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to read PHP variables.

2005-07-15 Thread Edward Vermillion

Bruno B B Magalhães wrote:

Hi everybody,

well I don´t want to include and use those variables or  set then. I  
want to read the file, parse the vars to a form, so the user can  change 
the system configs using the web instead of FTP...


I am thinking reading using a simple include, and then clean the file  
contents and write the strings..


Best Regards,
Bruno B B Magalhães

One simple way that I've done that in the past is to have a file, which 
is a basic php file like:


?php

$INFO['prefix_sectionInForm'] = 'whatever';

?


Include that file then do

foreach( $INFO as $in_key = $in_val )
{
if( preg_match(/prefix_/, $in_key) )
{
$db_info[$in_key] = $in_val;
}
}
foreach( $db_info as $in_key = $in_val )
{
$text = ucfirst(substr( $in_key, however long the prefix is ));
$print Some descroptor based on the prefix.$text
input type='text' name='$in_key' value='in_val' /
}

Then just write it all back out on the form processor part, with some 
security checking of course:


$file_string = ?php\n;

$update is an array with the key values I want..

foreach( $update as $info_key )
{
foreach( $input as $in_key = $in_val )
{
if( $info_key == $in_key )
{
$new[$info_key] = $in_val;
}
}
}

foreach( $new as $k = $v )
{
$file_string .= \$INFO[.'.$k.'.]\t\t\t=\t\.$v.\;\n;
}

$file_string .= \n.'?'.'';

Write $file_string back out to the config file.

Like I said, there's more to the script than this, error checks, seurity 
checks and the like, but this is the 'meat' of it all.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to read PHP variables.

2005-07-15 Thread André Medeiros
What about...

form action=saveConfig.php method=post

Database Host: input type=text name=config[database][host]
value=?=$config['database']['host']? /br /
Database User: input type=text name=config[database][user]
value=?=$config['database']['user']? /br /

!-- some more fields here --

/form

And then...

?php
$newConfigValues = $_POST['config'];

$fileCode = ?php\n// AUTOMATICLLY CREATED CONFIG FILE. DO NOT EDIT!
\n;
foreach( $newConfigValues as $parentConfigKey = $parentConfigValue ) {
if( is_array( $parentConfigValue ) {
foreach( $parentConfigValue as $childConfigKey = 
$childConfigValue )
{

$fileCode .= 
$config['$parentConfigKey']['$childConfigKey'] =
'$childConfigValue';\n;

}
}
else {
$fileCode .= $config['$parentConfigKey'] = 
'$parentConfigValue'\n;
}
}

$fileCode .= ?;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to read PHP variables.

2005-07-14 Thread Rory Browne
Thsi is way, way WAY too vague. 

What exactly do you need a patern for?

If you simply want to change it, then just do a $var['whatever'] =
value; again in the module you want to change it in. If you want to
redo the config file, then you can just loop through the array,
printing out, each value of the array as you go. Otherwise you could
just use var_export().

On 7/12/05, Bruno B B Magalhães [EMAIL PROTECTED] wrote:
 Hi you all!
 
 That's my problem: I have a configuration files with the following
 structure...
 
 $vars['varname'] = 'varvalue';
 
 And I would like to have a module to change those parameters, but I
 don't know how to write a pattern to match it...
 
 Thanks in advance...
 
 Best Regards,
 Bruno B B Magalhaes
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: How to read PHP variables.

2005-07-13 Thread Jasper Bryant-Greene

Bruno B B Magalhães wrote:
That's my problem: I have a configuration files with the following  
structure...


$vars['varname'] = 'varvalue';


If you trust the config file:

?php
eval(file_get_contents('/path/to/config.file'));
?

Jasper

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to read PHP variables.

2005-07-12 Thread Bruno B B Magalhães

Hi you all!

That's my problem: I have a configuration files with the following  
structure...


$vars['varname'] = 'varvalue';

And I would like to have a module to change those parameters, but I  
don't know how to write a pattern to match it...


Thanks in advance...

Best Regards,
Bruno B B Magalhaes

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] How to read PHP variables.

2005-07-12 Thread yanghshiqi
Firstly, I don't know why you want to change your configuration in real
time?
Then if you just keep your configuration in an array, then when you want to
change and use it in your script, you can just $vars['varname'] = sth
else.
So pls give us more detail.

 
 
 
Best regards,
Shiqi Yang

-Original Message-
From: Bruno B B Magalhães [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 12, 2005 8:21 PM
To: php-general@lists.php.net
Subject: [PHP] How to read PHP variables.

Hi you all!

That's my problem: I have a configuration files with the following  
structure...

$vars['varname'] = 'varvalue';

And I would like to have a module to change those parameters, but I  
don't know how to write a pattern to match it...

Thanks in advance...

Best Regards,
Bruno B B Magalhaes

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to read PHP variables.

2005-07-12 Thread Ahmed Saad
Hi Bruno,

On 7/12/05, Bruno B B Magalhães [EMAIL PROTECTED] wrote:
 Hi you all!
 $vars['varname'] = 'varvalue';
 
 And I would like to have a module to change those parameters, but I
 don't know how to write a pattern to match it...

i think you mean an API to help you manage and persist your
application settings (something more or less like the Preferences API
in java) and your format have to be much simpler like .ini format (key
= value) or some variation

take a look at phpclasses.org search results for ini
http://www.google.com/custom?domains=www.phpclasses.orgq=inisa=Searchsitesearch=www.phpclasses.orgclient=pub-2951707118576741forid=1channel=5742870948ie=ISO-8859-1oe=ISO-8859-1cof=GALT%3A%23663399%3BGL%3A1%3BDIV%3A%2322%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AA3C5CC%3BLBGC%3AA3C5CC%3BALC%3AFF%3BLC%3AFF%3BT%3A00%3BGFNT%3AFF%3BGIMP%3AFF%3BLH%3A50%3BLW%3A256%3BL%3Ahttp%3A%2F%2Ffiles.phpclasses.org%2Fgraphics%2Fgooglesearch.jpg%3BS%3Ahttp%3A%2F%2Fwww.phpclasses.org%2Fsearch.html%3BFORID%3A1%3Bhl=en

an alternative way is using XML to store your settings and use the PHP
XML support for parsing/manipulating these files.

-ahmed

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables in stored txt

2005-06-01 Thread Richard Lynch
On Tue, May 31, 2005 12:18 pm, Niels Riis Kristensen said:
 Hi. I have a problem that consist of a desire to use preformatted
 text in a while-loop while inserting data from another search. The
 code is as follows:


 

 $get_var1 = mysql_query(SELECT * FROM table1 WHERE id LIKE '1' LIMIT
 1);
  while($record=mysql_fetch_assoc($get_var1))
  {
  $show_var = $record['text'];
  }

Your first problem is this:

You loop through every record in table1, and you stuff it into $show_var...

But you are REPLACING the contents of $show_var each time, so you only end
up with the *LAST* record in $show_var.

You need to either concatenate to $show_var to dump *all* the data into
one big long text, or you need to move all the code below *inside* the
loop to do whatever you are trying to do to EACH $show_var, one after
another.

 $result = mysql_query(SELECT * FROM table2 WHERE kind LIKE '20');
  while($record=mysql_fetch_assoc($result))
  {
  echo   html
  head
  meta http-equiv='content-type' content='text/
 html;charset=iso-8859-1'
  titletest/title
  /head
  body bgcolor='#ff'
  table width='100%' border='0' cellspacing='2'
 cellpadding='0' height='50'
  tr
  tdimg src='../../../Media/HMLogo.gif'
 alt='' height='40' width='147' border='0'/td
  td/td
  td/td
  /tr
  /table
  table width='100%' border='0' cellspacing='2'
 cellpadding='0'
  tr height='526'
  td width='100%' height='600'
  .$show_var.
  /td
  /tr
  /table
  /body
  /html;
  print 
  script type='text/javascript'
  window.print();
  /script;
  }

These sems okay, I guess, though I'd get rid of the HTML inside of quotes
thing and use a heredoc or just break out of PHP and put ?php echo
$show_var? in the middle of a good long chunk of HTML.

I'm not really sure what you're trying to *DO* mind you...  Maybe you only
wanted the LAST record from table1 in the first place...  I sure doubt it
though.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Variables in stored txt

2005-05-31 Thread Niels Riis Kristensen
Hi. I have a problem that consist of a desire to use preformatted  
text in a while-loop while inserting data from another search. The  
code is as follows:





$get_var1 = mysql_query(SELECT * FROM table1 WHERE id LIKE '1' LIMIT  
1);

while($record=mysql_fetch_assoc($get_var1))
{
$show_var = $record['text'];
}


$result = mysql_query(SELECT * FROM table2 WHERE kind LIKE '20');
while($record=mysql_fetch_assoc($result))
{
echo   html
head
meta http-equiv='content-type' content='text/ 
html;charset=iso-8859-1'

titletest/title
/head
body bgcolor='#ff'
table width='100%' border='0' cellspacing='2'  
cellpadding='0' height='50'

tr
tdimg src='../../../Media/HMLogo.gif'  
alt='' height='40' width='147' border='0'/td

td/td
td/td
/tr
/table
table width='100%' border='0' cellspacing='2'  
cellpadding='0'

tr height='526'
td width='100%' height='600'
.$show_var.
/td
/tr
/table
/body
/html;
print 
script type='text/javascript'
window.print();
/script;
}

_

Needles to say, I hope, that it doesn't work!


Niels Riis Kristensen
([EMAIL PROTECTED])

NRK Group
- Electronic Music Engraving
- Webhosting
- Dynamic Web design
- E-Lists hosting

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Variables in stored txt

2005-05-31 Thread Jay Blanchard
Quite sending this over and over.it is taking a while for the e-mail
to get to the list

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables in stored txt

2005-05-31 Thread Niels Riis Kristensen

Oh, I get it. I have been very poor at explaining my problem.

I have a table, table1, in which I have standard text for letters. I  
would like to put data from table2 in the letters, so that the data  
is automatically placed in the letter through code in the standard  
text. It sounds complicated, I know, but I hope I make myself clear.  
English is not my native language.


What happens is, that the $show_var IS displayed. What I in my  
frustration haven't conveyed properly is, that the text in table1 in  
the the form



ordinary text to output to html . 
$var_from_the_result_query_on_table2. some more html text



shows up just like that, no data from table2 is processed. I know  
that I am probably using the wrong function, but I can't seem to find  
one.


And the reason I use SELECT * is that there is more than one field I  
need to output. There is only one in the example so that the post  
wouldn't be to voluminous.






Niels Riis Kristensen
([EMAIL PROTECTED])

NRK Group
- Electronic Music Engraving
- Webhosting
- Dynamic Web design
- E-Lists hosting


On 31/05/2005, at 22.53, [EMAIL PROTECTED] wrote:


which are you saying doesn't work?

  - outputting the value of $show_var in the html that follows

 or

  - outputting values from this query:

   mysql_query(SELECT * FROM table2 WHERE kind LIKE '20')


from what i can tell, you never actually retrieve values from this
second query.

if the issue is displaying $show_var, you should put a debug in
between these two points, e.g.:

 {
 $show_var = $record['text'];
 }

   $debug = 4;

   if ($debug  3) {
 print show_var: $show_varP\n;
   }


  $result = mysql_query(SELECT * FROM table2 WHERE kind LIKE '20');


so that you actually know that your first data query/retrieval has
worked.
separately, why are you doing a select *  when, in the first case
at least, you seem to only want the value from the field text. if
you only want values from specific fields you should enumerate them
on the select as a select *  is very inefficient. also, using the
like operator, when you really should be using the = operator
isn't efficient either.


 Original Message 


Date: Tuesday, May 31, 2005 09:18:42 PM +0200
From: Niels Riis Kristensen [EMAIL PROTECTED]
To: php-general@lists.php.net
Cc:
Subject: [PHP] Variables in stored txt

Hi. I have a problem that consist of a desire to use preformatted
text in a while-loop while inserting data from another search. The
code is as follows:




$get_var1 = mysql_query(SELECT * FROM table1 WHERE id LIKE '1'
LIMIT  1);
 while($record=mysql_fetch_assoc($get_var1))
 {
 $show_var = $record['text'];
 }


$result = mysql_query(SELECT * FROM table2 WHERE kind LIKE '20');
 while($record=mysql_fetch_assoc($result))
 {
 echo   html
 head
 meta http-equiv='content-type' content='text/
html;charset=iso-8859-1'
 titletest/title
 /head
 body bgcolor='#ff'
 table width='100%' border='0' cellspacing='2'
cellpadding='0' height='50'
 tr
 tdimg
src='../../../Media/HMLogo.gif'  alt='' height='40' width='147'
border='0'/td
 td/td
 td/td
 /tr
 /table
 table width='100%' border='0' cellspacing='2'
cellpadding='0'
 tr height='526'
 td width='100%' height='600'
 .$show_var.
 /td
 /tr
 /table
 /body
 /html;
 print 
 script type='text/javascript'
 window.print();
 /script;
 }

_

Needles to say, I hope, that it doesn't work!


Niels Riis Kristensen
([EMAIL PROTECTED])

NRK Group
- Electronic Music Engraving
- Webhosting
- Dynamic Web design
- E-Lists hosting

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- End Original Message --





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP variables on SSL and IE5.x

2004-12-28 Thread Merlin
Hi there,
I am having trouble with posting a form to a php script through SSL on IE prior 
5.5 sp1. It works like a charm on all other browsers. In IE it works without 
SSL, but when SSL is enabled, the browser pops up with a message that he is 
switching to an unsecure site and then all then displays a 404 error with the 
correct php file url inside the Adressbar. I guess the browser is somehow 
loosing all variables submited via post.

Has anybody an idea how to solve that? I cant unfortunatelly provide a link, 
since I had to disable SSL on the productio server due to that error.

Thank you for any help on that,
Merlin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] php variables in a backtick command

2004-12-11 Thread Jonathan Duncan
I am trying to run a shell command with backticks.  However, I get a parse 
error.  Is it because I have an array variable in there?

$result = `adduser -l=$dist_id -p=$user['password'] --f=$user['name_first'] 
$user['name_last']`;

Do I need to assign the value to a regular variable before I put it in 
there?  Like this?

$pword=$user['password']
$fname =$user['name_first']
$lname =$user['name_last']
$result = `adduser -l=$dist_id -p=$pword --f=$fname $lname`;

Thanks,
Jonathan 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php variables in a backtick command

2004-12-11 Thread Sebastian
well $user['password'] has no double quotes around it.

- Original Message - 
From: Jonathan Duncan [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, December 11, 2004 8:09 PM
Subject: [PHP] php variables in a backtick command


 I am trying to run a shell command with backticks.  However, I get a parse
 error.  Is it because I have an array variable in there?

 $result =
`adduser -l=$dist_id -p=$user['password'] --f=$user['name_first']
 $user['name_last']`;

 Do I need to assign the value to a regular variable before I put it in
 there?  Like this?

 $pword=$user['password']
 $fname =$user['name_first']
 $lname =$user['name_last']
 $result = `adduser -l=$dist_id -p=$pword --f=$fname $lname`;

 Thanks,
 Jonathan

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php variables in a backtick command

2004-12-11 Thread Jonathan Duncan
Ah, that is a good idea, putting the command in a variable and then 
executing the variable.  I have doen that before but did not think of it 
now.  Too many things going on.  Thanks!

Jonathan

Rory Browne [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 I'm not sure about variable expansion with backticks(I don't use
 backticks, if necessary I use shell_exec() instead). I'm just after
 installing a fresh SuSE 9.1, and php is giving me a segfault at the
 minute, with that particular code, but if you were using double quotes
 you could:

 $command = adduser -l=$dist_id -p={$user['password']}
 --f=\{$user['name_first']} {$user['name_last']}\;

 bearing in mind that the variables have been {}'ed, and your double
 quote around $user['name_first'] and ['name_last']) has been escaped
 to \

 you can use shell_exec($command), which is identical to the backtick 
 operation.

 Having that said, you should consider using alternative program
 execution instead, instead of using the shell. What do you need the
 shell for? You might(albeit unlikely) also come across a situation
 where the shell is something like /bin/false, or /bin/falselogin, or
 /bin/scponly, or basicly something that doesn't particularly work that
 well as a shell.

 Rory

 On Sat, 11 Dec 2004 18:09:17 -0700, Jonathan Duncan [EMAIL PROTECTED] 
 wrote:
 I am trying to run a shell command with backticks.  However, I get a 
 parse
 error.  Is it because I have an array variable in there?

 $result = 
 `adduser -l=$dist_id -p=$user['password'] --f=$user['name_first']
 $user['name_last']`;

 Do I need to assign the value to a regular variable before I put it in
 there?  Like this?

 $pword=$user['password']
 $fname =$user['name_first']
 $lname =$user['name_last']
 $result = `adduser -l=$dist_id -p=$pword --f=$fname $lname`;

 Thanks,
 Jonathan

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php variables in a backtick command

2004-12-11 Thread Jonathan Duncan
The quotes are only for the shell command which does not use quotes around 
password.  Thanks for the feedback.

Jonathan


Sebastian [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 well $user['password'] has no double quotes around it.

 - Original Message - 
 From: Jonathan Duncan [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Saturday, December 11, 2004 8:09 PM
 Subject: [PHP] php variables in a backtick command


 I am trying to run a shell command with backticks.  However, I get a 
 parse
 error.  Is it because I have an array variable in there?

 $result =
 `adduser -l=$dist_id -p=$user['password'] --f=$user['name_first']
 $user['name_last']`;

 Do I need to assign the value to a regular variable before I put it in
 there?  Like this?

 $pword=$user['password']
 $fname =$user['name_first']
 $lname =$user['name_last']
 $result = `adduser -l=$dist_id -p=$pword --f=$fname $lname`;

 Thanks,
 Jonathan

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php variables in a backtick command

2004-12-11 Thread Jonathan Duncan
So I tried it that way and it worked, that is annoying though, having to add 
extra lines to the code and assign the contents of one variable to another. 
Any way around this?

Jonathan


Jonathan Duncan [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
I am trying to run a shell command with backticks.  However, I get a parse 
error.  Is it because I have an array variable in there?

 $result = 
 `adduser -l=$dist_id -p=$user['password'] --f=$user['name_first'] 
 $user['name_last']`;

 Do I need to assign the value to a regular variable before I put it in 
 there?  Like this?

 $pword=$user['password']
 $fname =$user['name_first']
 $lname =$user['name_last']
 $result = `adduser -l=$dist_id -p=$pword --f=$fname $lname`;

 Thanks,
 Jonathan 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] php variables in a backtick command

2004-12-11 Thread Rory Browne
I'm not sure about variable expansion with backticks(I don't use
backticks, if necessary I use shell_exec() instead). I'm just after
installing a fresh SuSE 9.1, and php is giving me a segfault at the
minute, with that particular code, but if you were using double quotes
you could:

$command = adduser -l=$dist_id -p={$user['password']}
--f=\{$user['name_first']} {$user['name_last']}\;

bearing in mind that the variables have been {}'ed, and your double
quote around $user['name_first'] and ['name_last']) has been escaped
to \

you can use shell_exec($command), which is identical to the backtick operation.

Having that said, you should consider using alternative program
execution instead, instead of using the shell. What do you need the
shell for? You might(albeit unlikely) also come across a situation
where the shell is something like /bin/false, or /bin/falselogin, or
/bin/scponly, or basicly something that doesn't particularly work that
well as a shell.

Rory

On Sat, 11 Dec 2004 18:09:17 -0700, Jonathan Duncan [EMAIL PROTECTED] wrote:
 I am trying to run a shell command with backticks.  However, I get a parse
 error.  Is it because I have an array variable in there?
 
 $result = `adduser -l=$dist_id -p=$user['password'] --f=$user['name_first']
 $user['name_last']`;
 
 Do I need to assign the value to a regular variable before I put it in
 there?  Like this?
 
 $pword=$user['password']
 $fname =$user['name_first']
 $lname =$user['name_last']
 $result = `adduser -l=$dist_id -p=$pword --f=$fname $lname`;
 
 Thanks,
 Jonathan
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Variables from database

2004-12-05 Thread Stuart Felenstein
I haven't try this yet but wondering if it's possible.
 
Can I do something like this:

select fieldone from table ;

$myvar = $fieldone ?

And more so could I do it with a where clause ?

i.e. select fieldone from table where fieldone = 3

$myvar = $fieldone ?

This is probably a stupid question.  I am also
wondering about syntax.

Thank you,
Stuart

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variables from database

2004-12-05 Thread Marek Kilimajer
Stuart Felenstein wrote:
I haven't try this yet but wondering if it's possible.
 
Can I do something like this:

select fieldone from table ;
$myvar = $fieldone ?
And more so could I do it with a where clause ?
i.e. select fieldone from table where fieldone = 3
$myvar = $fieldone ?
This is probably a stupid question.  I am also
wondering about syntax.
you can use extract()
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


  1   2   3   4   5   >