php-general Digest 2 Oct 2011 08:52:00 -0000 Issue 7501

Topics (messages 315097 through 315110):

Re: php.ini setting
        315097 by: Stephen
        315098 by: Jim Giner
        315099 by: Ashley Sheridan
        315101 by: Mike Mackintosh
        315103 by: Jim Giner
        315108 by: Jim Giner
        315110 by: Ashley Sheridan

Variable question
        315100 by: Ron Piggott
        315102 by: Mike Mackintosh
        315104 by: David Harkness
        315105 by: Robert Cummings
        315106 by: Tim Streater
        315109 by: Geoff Shang

Re: Getting meta data (of any type) for an XML file being from it's URL.
        315107 by: Tommy Pham

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 11-10-01 11:57 AM, Jim Giner wrote:
I'm trying to set magic quotes Off as my reading tells me that it's not good
to have it defaulted to On.


http://php.net/manual/en/security.magicquotes.disabling.php

Stephen

--- End Message ---
--- Begin Message ---
"Stephen" <stephe...@rogers.com> wrote in message 
news:4e874606.2030...@rogers.com...
>>
> http://php.net/manual/en/security.magicquotes.disabling.php
>
> Stephen

That tells me nothing new. 



--- End Message ---
--- Begin Message ---
On Sat, 2011-10-01 at 12:55 -0400, Stephen wrote:

> On 11-10-01 11:57 AM, Jim Giner wrote:
> > I'm trying to set magic quotes Off as my reading tells me that it's not good
> > to have it defaulted to On.
> >
> >
> http://php.net/manual/en/security.magicquotes.disabling.php
> 
> Stephen
> 


Stephen, that page specifies the exact same line for the .htaccess that
he said he used. I'm not sure why it would cause an internal server
error, but I've seen some Apache configurations completely flake over
lines in the .htaccess that were fine elsewhere.

The only thing I can find online where this line will cause a server
error is where the server is set up to allow custom php.ini files which
override the defaults. To test this, try adding a php.ini file into the
directory your script is (this is completely untested, I just saw it on
a forum (http://www.bluehostforum.com/archive/index.php/t-15975.html ))
and enter the regular php.ini line to turn it off.

If that fails, I'd try and contact your hosting provider and see what
they say, as they probably have more information specific to this
problem, as it's most likely a setting of theirs that is causing it.

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



--- End Message ---
--- Begin Message ---
On Oct 1, 2011, at 2:04 PM, Ashley Sheridan wrote:

> On Sat, 2011-10-01 at 12:55 -0400, Stephen wrote:
> 
>> On 11-10-01 11:57 AM, Jim Giner wrote:
>>> I'm trying to set magic quotes Off as my reading tells me that it's not good
>>> to have it defaulted to On.
>>> 
>>> 
>> http://php.net/manual/en/security.magicquotes.disabling.php
>> 
>> Stephen
>> 
> 
> 
> Stephen, that page specifies the exact same line for the .htaccess that
> he said he used. I'm not sure why it would cause an internal server
> error, but I've seen some Apache configurations completely flake over
> lines in the .htaccess that were fine elsewhere.
> 
> The only thing I can find online where this line will cause a server
> error is where the server is set up to allow custom php.ini files which
> override the defaults. To test this, try adding a php.ini file into the
> directory your script is (this is completely untested, I just saw it on
> a forum (http://www.bluehostforum.com/archive/index.php/t-15975.html ))
> and enter the regular php.ini line to turn it off.
> 
> If that fails, I'd try and contact your hosting provider and see what
> they say, as they probably have more information specific to this
> problem, as it's most likely a setting of theirs that is causing it.
> 
> -- 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 


Have you tried:

ini_set('magic_quotes_gpc', false);

--- End Message ---
--- Begin Message ---
"Mike Mackintosh" <mike.mackint...@angrystatic.com> wrote in message 
news:52ea6b9e-ef12-44d3-bd31-72984e5e5...@angrystatic.com...

<Have you tried:
<ini_set('magic_quotes_gpc', false);=

I'm trying to set it directly and not have to incl in every script I write. 



--- End Message ---
--- Begin Message ---
Solved.

Had to have my host provider put a copy of php.ini in my public_html and 
then I made the magic quotes setting change.

Interesting - running a phpinfo command still shows the setting as On 
becuase it returns the server's settigns, NOT my individual folder setting.



--- End Message ---
--- Begin Message ---
On Sat, 2011-10-01 at 14:01 -0400, Mike Mackintosh wrote:

> On Oct 1, 2011, at 2:04 PM, Ashley Sheridan wrote:
> 
> > On Sat, 2011-10-01 at 12:55 -0400, Stephen wrote:
> > 
> >> On 11-10-01 11:57 AM, Jim Giner wrote:
> >>> I'm trying to set magic quotes Off as my reading tells me that it's not 
> >>> good
> >>> to have it defaulted to On.
> >>> 
> >>> 
> >> http://php.net/manual/en/security.magicquotes.disabling.php
> >> 
> >> Stephen
> >> 
> > 
> > 
> > Stephen, that page specifies the exact same line for the .htaccess that
> > he said he used. I'm not sure why it would cause an internal server
> > error, but I've seen some Apache configurations completely flake over
> > lines in the .htaccess that were fine elsewhere.
> > 
> > The only thing I can find online where this line will cause a server
> > error is where the server is set up to allow custom php.ini files which
> > override the defaults. To test this, try adding a php.ini file into the
> > directory your script is (this is completely untested, I just saw it on
> > a forum (http://www.bluehostforum.com/archive/index.php/t-15975.html ))
> > and enter the regular php.ini line to turn it off.
> > 
> > If that fails, I'd try and contact your hosting provider and see what
> > they say, as they probably have more information specific to this
> > problem, as it's most likely a setting of theirs that is causing it.
> > 
> > -- 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> > 
> 
> 
> Have you tried:
> 
> ini_set('magic_quotes_gpc', false);


That won't work, because by the time the server comes to process the
script, the data has already been processed. In effect, that line will
do nothing.

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



--- End Message ---
--- Begin Message ---
If $correct_answer has a value of 3 what is the correct syntax needed to use 
echo to display the value of $trivia_answer_3?

I know this is incorrect, but along the lines of what I am wanting to do:

echo $trivia_answer_$correct_answer;

$trivia_answer_1 = “1,000”;
$trivia_answer_2 = “1,250”;
$trivia_answer_3 = “2,500”;
$trivia_answer_4 = “5,000”;

Ron




www.TheVerseOfTheDay.info 

--- End Message ---
--- Begin Message ---
On Oct 1, 2011, at 1:59 PM, Ron Piggott wrote:

> 
> If $correct_answer has a value of 3 what is the correct syntax needed to use 
> echo to display the value of $trivia_answer_3?
> 
> I know this is incorrect, but along the lines of what I am wanting to do:
> 
> echo $trivia_answer_$correct_answer;
> 
> $trivia_answer_1 = “1,000”;
> $trivia_answer_2 = “1,250”;
> $trivia_answer_3 = “2,500”;
> $trivia_answer_4 = “5,000”;
> 
> Ron
> 
> 
> 
> 
> www.TheVerseOfTheDay.info 

Best bet would to toss this into either an object or array for simplification, 
otherwise that type of syntax would need the use of eval.

example:  eval('echo $trivia_answer_'.$correct_answer.';');

best bet would be to..

$trivia_answer = array();

$trivia_answer[1] = 1000;
$trivia_answer[2] = 1250;
$trivia_answer[3] = 2500;
$trivia_answer[4] = 5000;

echo $trivia_answer[$correct_answer];


--- End Message ---
--- Begin Message ---
On Sat, Oct 1, 2011 at 10:59 AM, Ron Piggott <ron....@actsministries.org>wrote:

> If $correct_answer has a value of 3 what is the correct syntax needed to
> use echo to display the value of $trivia_answer_3?


You can use variable variables [1] to access the variable by building its
name in a string:

    $name = 'trivia_answer_' . $correct_answer;
    echo $$name;

Peace,
David

[1] http://php.net/manual/en/language.variables.variable.php

--- End Message ---
--- Begin Message ---
On 11-10-01 02:03 PM, Mike Mackintosh wrote:

On Oct 1, 2011, at 1:59 PM, Ron Piggott wrote:


If $correct_answer has a value of 3 what is the correct syntax needed to use 
echo to display the value of $trivia_answer_3?

I know this is incorrect, but along the lines of what I am wanting to do:

echo $trivia_answer_$correct_answer;

$trivia_answer_1 = “1,000”;
$trivia_answer_2 = “1,250”;
$trivia_answer_3 = “2,500”;
$trivia_answer_4 = “5,000”;

Ron




www.TheVerseOfTheDay.info

Best bet would to toss this into either an object or array for simplification, 
otherwise that type of syntax would need the use of eval.

example:  eval('echo $trivia_answer_'.$correct_answer.';');

best bet would be to..

$trivia_answer = array();

$trivia_answer[1] = 1000;
$trivia_answer[2] = 1250;
$trivia_answer[3] = 2500;
$trivia_answer[4] = 5000;

echo $trivia_answer[$correct_answer];

Agreed the OP's value list isn't optimal, but eval is not needed to address the solution:

<?php

    $trivia_answer_1 = "1,000";
    $trivia_answer_2 = "1,250";
    $trivia_answer_3 = "2,500";
    $trivia_answer_4 = "5,000";

    $answer
        = isset( ${'trivia_answer_'.$correct_answer} )
        ? ${'trivia_answer_'.$correct_answer}
        : 'Not found';

    echo $answer."\n";
?>

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On 01 Oct 2011 at 18:59, Ron Piggott <ron....@actsministries.org> wrote: 

> If $correct_answer has a value of 3 what is the correct syntax needed to use
> echo to display the value of $trivia_answer_3?
>
> I know this is incorrect, but along the lines of what I am wanting to do:
>
> echo $trivia_answer_$correct_answer;
>
> $trivia_answer_1 = “1,000”;
> $trivia_answer_2 = “1,250”;
> $trivia_answer_3 = “2,500”;
> $trivia_answer_4 = “5,000”;

Not completely obvious to me what you're trying to do but I assume its:

echo '\$trivia_answer_' . $correct_answer . " = \"" . $somevalue . "\";"; 

--
Cheers  --  Tim

--- End Message ---
--- Begin Message ---
On Sat, 1 Oct 2011, Mike Mackintosh wrote:

Best bet would to toss this into either an object or array for simplification, otherwise that type of syntax would need the use of eval.

example:  eval('echo $trivia_answer_'.$correct_answer.';');

You could do:

$var = "trivia_answer_.$correct_answer";
echo $$var;

But I agree that an array would be simpler.

best bet would be to..

$trivia_answer = array();

$trivia_answer[1] = 1000;
$trivia_answer[2] = 1250;
$trivia_answer[3] = 2500;
$trivia_answer[4] = 5000;

echo $trivia_answer[$correct_answer];

You can define this a bit more simply:

$trivia_answer = array (
  1 => 1000,
  2 => 1250,
  3 => 2500,
  4 => 5000
);

You can do it even more simply by just giving the values, but indexes wil start at 0:

<?php
$trivia_answer = array (1000, 1250, 2500, 5000);
print_r ($trivia_answer);
?>

Array
(
    [0] => 1000
    [1] => 1250
    [2] => 2500
    [3] => 5000
)

While manually defining an array like this is only slightly less tedius than using 4 numbered variables, it's a lot easier to do if you're getting data from somewhere else (e.g. a database of trivia questions). To use the original way proposed, you'd have to keep constructing variable names, which arrays avoid quite nicely.

In my opinion, the only real usefulness for a syntax like $$var (above) is if you want to do something with a bunch of variables in one go. For example:

foreach (array ("title", "artist", "album", "label") as $field)
  echo ucwords($field) . ': ' . $$field . '<BR>';

The above comes from a function which manages only a single record, so no real need to use an array. I could of course, e.g. record['title'] etc, but I don't see much could be gained unless I needed to be able to manage an entire record as a single unit.

Geoff.

--- End Message ---
--- Begin Message ---
On Fri, Sep 30, 2011 at 3:03 AM, Richard Quadling <rquadl...@gmail.com>wrote:

> On 29 September 2011 23:34, Tommy Pham <tommy...@gmail.com> wrote:
> > On Thu, Sep 29, 2011 at 3:27 PM, Tommy Pham <tommy...@gmail.com> wrote:
> >>
> >> On Thu, Sep 29, 2011 at 9:09 AM, Richard Quadling <rquadl...@gmail.com>
> >> wrote:
> >>>
> >>> Hi.
> >>>
> >>> I'm looking to process very large XML files without the need of first
> >>> downloading them.
> >>>
> >>> To that end,
> >>> SimpleXMLIterator('compress.zlib://http://www.site.com/products.xml.gz
> ')
> >>> is working perfectly.
> >>>
> >>> But a downside is that I have no information of my progress.
> >>>
> >>> Is there any mechanism available to get a position within the XML
> stream?
> >>>
> >>> I can use libxml_set_streams_context() to set a context (so I can
> >>> provide POST data if needed for the HTTP request), but I can't see how
> >>> to gain access to the stream within the libxml code (SimpleXML uses
> >>> libxml).
> >>>
> >>> At the most basic, what I'm looking for is to be able to record a
> >>> percentage complete. Even with compression, I'll be reading some bytes
> >>> from a stream (either from http or from compress.zlib) and I want to
> >>> know where I am in that stream.
> >>>
> >>> The HTTP header will tell me how big the file is (so that can easily
> >>> be a HEAD request to get that data).
> >>>
> >>>
> >>> Even if I DO save the file locally first, I still can't get a position.
> >>>
> >>> If I use the SimpleXMLIterator::count() method, I am unsure as to what
> >>> will happen if I am using a stream (rather than a local file). If I
> >>> use ...
> >>>
> >>> $xml = new SimpleXMLIterator(...);
> >>> $items = $xml->count();
> >>> foreach($xml as $s_Tag => $o_Item) {
> >>>  ...
> >>> }
> >>>
> >>> will the XML file be cached somewhere? Or will that depend upon the
> >>> originating server supporting some sort of rewind/chunk mechanism?
> >>>
> >>>
> >>>
> >>> Any suggestions/ideas?
> >>>
> >>>
> >>>
> >>> Richard.
> >>>
> >>>
> >>> --
> >>> Richard Quadling
> >>> Twitter : EE : Zend : PHPDoc
> >>> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
> >>>
> >>
> >> Richard,
> >>
> >> Only think I can think of is break up into 2 parts.  1st part use cURL
> for
> >> the down streams and monitor it's progress.  2nd part is XML parsing.
> If
> >> you want to do both simultaneously and only if the remote supports
> chunked
> >> encoding/transfer, you could use multiple handles of cURL into numerical
> >> indexed array variable containing the chunks for XML parsing.  This
> could be
> >> memory intensive if the file is very large, depending whether you free
> the
> >> elements in the array as you progress.  So if memory consumption is a
> major
> >> concern, you may want to save to the file locally until the
> import/migration
> >> is done as there maybe a situation where you'll need to review the data
> and,
> >> thus, saving the time and bandwidth of having to re-download the data.
> >>
> >> Regards,
> >> Tommy
> >
> > An afterthought,  handling streams and parsing at the same may require
> > sophisticated XML node validations as the node maybe split between the
> > transferred chunks.
> >
>
> The SimpleXMLIterator() does do a superb job of providing 1 node at a
> time and doesn't remember each node automatically. If I do, then
> that's my issue.
>
> Accessing the stream/file meta data doesn't seem possible.
>
>
> --
> Richard Quadling
> Twitter : EE : Zend : PHPDoc
> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
>

A while back, I did a project in Java where parts of it had to access and
process streams.  I guess this would be a really good exercise for me to see
if it's doable in PHP also.  In addition to implement 'PHP simulating
threads', in this scenario, where 1 thread would download and monitor the
streams while another thread would analyze/process the data and import into
a database.

--- End Message ---

Reply via email to