php-general Digest 27 Nov 2006 07:21:01 -0000 Issue 4482

Topics (messages 245155 through 245168):

Re: Self generating variables/arrays
        245155 by: jekillen
        245166 by: Richard Lynch

Re: Negative memory_get_usage() Values
        245156 by: Chris
        245159 by: Chris
        245165 by: Richard Lynch

<?=$var?> on OS X
        245157 by: Brian Dunning
        245158 by: Chris
        245160 by: Dotan Cohen
        245161 by: Chris
        245162 by: Dotan Cohen
        245163 by: Chris
        245164 by: Dotan Cohen

Re: PHP and XML
        245167 by: onewaylife

Re: backing up a database
        245168 by: David Robley

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

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


----------------------------------------------------------------------
--- Begin Message ---

On Nov 26, 2006, at 5:11 AM, Stut wrote:

jekillen wrote:
I am writing some code that will format results of a search for display. I need to split an array into several different arrays but I won't know
before hand how many, so, I am looking for a way to dynamically
generate arrays for this purpose.
My present direction is to use the following code:
for($i = 0; $i < $c; $i++)
    { eval('$a_'.$i.' = array();'); }
Where '$c' is the derived number of arrays need to hold the
pieces of the bigger array. My confusion, though, is; since
these are created in the scope of the for loop, I don't know
if I can use them elsewhere in the code. The Global statement
sends them outside the scope of the function this code is in,
or does it? And I'm not even sure I am on the right track.
Perhaps someone can say yay or nay on the spot, if not
I can go back and do some experimenting.

I'm not sure why you think you need to do this. In PHP you do not need to 'declare' variables, you can just use them. So unless you're checking for the existance of these arrays after this loop, the loop is completely pointless. But you haven't included enough information about how you intend to use these arrays to give a definite answer.

As far as scope goes, if you want to create these variables in the global scope, create them as elements of the $GLOBALS array [http://php.net/manual/en/ reserved.variables.php#reserved.variables.globals].

-Stut
Thanks for the reply;
The problem is
1. one large array exploded around \n
2. then a loop looks for '<br><br>\n' items
    and records the index number of these items
    as well of keeping a count: ($c)
3. Since $c is a variable it can represent a different
    number each time.
4. Since I don't know what $c is going to be I can't
   declare array variables with predetermined names
5. I want to slice the large array into $c arrays that
   begin and end around items in the large array
   containing '<br><br>\n';
This is as much abstraction as I can give you
In context it is represented by several hundred lines of function code.
This code is supposed to format the result of a search operation.
It is tailored for a custom application. I don't want to rewrite the
whole ball of wax just so I can use someone's wonderful pre
packaged code library or applications.
(I have gone ahead with experimenting with this code and
 was successful, up to a point...)
Thanks again;
JK



--- End Message ---
--- Begin Message ---
On Sun, November 26, 2006 3:45 pm, jekillen wrote:
> 1. one large array exploded around \n
> 2. then a loop looks for '<br><br>\n' items
>      and records the index number of these items
>      as well of keeping a count: ($c)
> 3. Since $c is a variable it can represent a different
>      number each time.
> 4. Since I don't know what $c is going to be I can't
>     declare array variables with predetermined names

You don't NEED to track the number of items:

PHP is happy to do that for you:

$a[$i][] = "next item";

> 5. I want to slice the large array into $c arrays that
>     begin and end around items in the large array
>     containing '<br><br>\n';
> This is as much abstraction as I can give you
> In context it is represented by several hundred lines of function
> code.

I strongly suspect that you could simplify your code to a large degree...

Post a small "slice" out of your data and see what folks think.

You may be taking a very long route to your destination...

-- 
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?

--- End Message ---
--- Begin Message --- Okay, I modified the script as follows to allow for collecting data and graphed it. The graph is at http://dented-planet.net/graph.png (sorry, I'm not versed in created perfect charts).

<?php

$x = '';

for ($i = 1; $i <= 20000; $i++) {

    $x = utf8_encode('this is a test');

    if ($i % 100 === 0) {
echo $i . ' ' . memory_get_usage() . ' ' . memory_get_usage (true) . "\n";
    }
}

?>

Chris
[EMAIL PROTECTED]



On Nov 26, 2006, at 12:34 PM, Richard Lynch wrote:

What version of PHP and what OS?

I *think* that there is some jiggery-pokery going on in
memory_get_usage() in PHP 5 and managed memory where it would make
perfect sense to get negative numbers occasionally...

You may also want to log the memory_get_usage inside the loop, and
then graph the memory usage as it goes up/down to get a better idea of
what's going on.

On Sun, November 26, 2006 8:35 am, Chris wrote:
Hey gang,

I'm getting a negative return value from memory_get_usage() using the
following script. My I've got --enable-memory-limit enabled  and my
memory_limit is set to 100MB (which should more than enough memory).

I suspect that there is a bug in utf8_encode() but I'd like others to
test it (on different platforms) before I submit it as a bug.

<?php

for ($i=0; $i < 20000; $i++) {
     echo utf8_encode('This is a test');
}

echo memory_get_usage();

?>


Chris
[EMAIL PROTECTED]

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




--
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?



--- End Message ---
--- Begin Message ---
Chris wrote:
Whoops,

I'm using PHP 5.2.0 on Mac OS X 10.4.8.

Memory usage in php5.2.0 has been changed:

http://www.php.net/UPDATE_5_2.txt

Under "Improved memory manager and increased default memory limit"

Not sure why you'd be getting negative values but I'm guessing it's related to those changes.

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

--- End Message ---
--- Begin Message ---
On Sun, November 26, 2006 3:27 pm, Chris wrote:
> Okay, I modified the script as follows to allow for collecting data
> and graphed it. The graph is at http://dented-planet.net/graph.png
> (sorry, I'm not versed in created perfect charts).

That's pretty weird...

I mean, something is not right with this picture...

You may want to file a bug report...

I suppose it's remotely possible that PHP is de-allocating more and
more memory as it realizes that you aren't using it anyway, but that
seems awfully unlikely...

-- 
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?

--- End Message ---
--- Begin Message --- I've got a new OS X box and for some reason <?=$var?> doesn't work like it does on all my other OS X boxes - anyone know a quick reason why not?
--- End Message ---
--- Begin Message ---
Brian Dunning wrote:
I've got a new OS X box and for some reason <?=$var?> doesn't work like it does on all my other OS X boxes - anyone know a quick reason why not?

Check your php.ini for short_open_tags.

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

--- End Message ---
--- Begin Message ---
On 27/11/06, Brian Dunning <[EMAIL PROTECTED]> wrote:
I've got a new OS X box and for some reason <?=$var?> doesn't work
like it does on all my other OS X boxes - anyone know a quick reason
why not?


Exactly for that reason I don't recommend that you use it. Just use
<?php print $var; ?> as it's portable and doesn't add that much
typing- certainly not enough to justify the headache.

Dotan Cohen

http://what-is-what.com/what_is/webpage.html
http://lyricslist.com/

--- End Message ---
--- Begin Message ---
Dotan Cohen wrote:
On 27/11/06, Brian Dunning <[EMAIL PROTECTED]> wrote:
I've got a new OS X box and for some reason <?=$var?> doesn't work
like it does on all my other OS X boxes - anyone know a quick reason
why not?


Exactly for that reason I don't recommend that you use it. Just use
<?php print $var; ?> as it's portable and doesn't add that much
typing- certainly not enough to justify the headache.

Good suggestion but it doesn't help if it's not his software that he needs to get running ;)

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

--- End Message ---
--- Begin Message ---
On 27/11/06, Chris <[EMAIL PROTECTED]> wrote:
Dotan Cohen wrote:
> On 27/11/06, Brian Dunning <[EMAIL PROTECTED]> wrote:
>> I've got a new OS X box and for some reason <?=$var?> doesn't work
>> like it does on all my other OS X boxes - anyone know a quick reason
>> why not?
>>
>
> Exactly for that reason I don't recommend that you use it. Just use
> <?php print $var; ?> as it's portable and doesn't add that much
> typing- certainly not enough to justify the headache.

Good suggestion but it doesn't help if it's not his software that he
needs to get running ;)

Actually, it does. He can global replace "<?=" with "<?php print" and
be done with it. Then he could let the author of this non-portable
software know that his 'shortcut' makes using the software difficult.

Especially if it's not his own code (ie, code meant to be used by
others) it should not depend upon short tags.

Dotan Cohen

http://dotancohen.com/
http://what-is-what.com/what_is/website.html

--- End Message ---
--- Begin Message ---
Dotan Cohen wrote:
On 27/11/06, Chris <[EMAIL PROTECTED]> wrote:
Dotan Cohen wrote:
> On 27/11/06, Brian Dunning <[EMAIL PROTECTED]> wrote:
>> I've got a new OS X box and for some reason <?=$var?> doesn't work
>> like it does on all my other OS X boxes - anyone know a quick reason
>> why not?
>>
>
> Exactly for that reason I don't recommend that you use it. Just use
> <?php print $var; ?> as it's portable and doesn't add that much
> typing- certainly not enough to justify the headache.

Good suggestion but it doesn't help if it's not his software that he
needs to get running ;)

Actually, it does. He can global replace "<?=" with "<?php print" and
be done with it. Then he could let the author of this non-portable
software know that his 'shortcut' makes using the software difficult.

Especially if it's not his own code (ie, code meant to be used by
others) it should not depend upon short tags.

Well he could also change it with a htaccess :P

php_flag short_open_tags on

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

--- End Message ---
--- Begin Message ---
On 27/11/06, Chris <[EMAIL PROTECTED]> wrote:
Dotan Cohen wrote:
> On 27/11/06, Chris <[EMAIL PROTECTED]> wrote:
>> Dotan Cohen wrote:
>> > On 27/11/06, Brian Dunning <[EMAIL PROTECTED]> wrote:
>> >> I've got a new OS X box and for some reason <?=$var?> doesn't work
>> >> like it does on all my other OS X boxes - anyone know a quick reason
>> >> why not?
>> >>
>> >
>> > Exactly for that reason I don't recommend that you use it. Just use
>> > <?php print $var; ?> as it's portable and doesn't add that much
>> > typing- certainly not enough to justify the headache.
>>
>> Good suggestion but it doesn't help if it's not his software that he
>> needs to get running ;)
>
> Actually, it does. He can global replace "<?=" with "<?php print" and
> be done with it. Then he could let the author of this non-portable
> software know that his 'shortcut' makes using the software difficult.
>
> Especially if it's not his own code (ie, code meant to be used by
> others) it should not depend upon short tags.

Well he could also change it with a htaccess :P

php_flag short_open_tags on


If it's for many files and he doesn't know perl (I don't either, but I
know that perl can search/replace many files with ease), then he could
override the php.ini settings in .htaccess. That, however, doesn't
solve the root problem: the use of short tags. If he needs the fix for
only one file, then open it in vi (or whatever gui app Macs use :) and
have at it.

Dotan Cohen
http://what-is-what.com/what_is/html_email.html
http://song-lirics.com/

--- End Message ---
--- Begin Message ---
hello all
I have created a simple xml file address.php i.e 
<?php
        $xmlstr = <<<XML
        <?xml version="1.0" ?>
                <!DOCTYPE AddressBook[
                <!ELEMENT AddressBook (person)+ >
                <!ELEMENT person (group,name,organization, address,email)>
                <!ELEMENT group (#PCDATA)>
                <!ELEMENT name (#PCDATA)>
                <!ELEMENT organization (#PCDATA)>
                <!ELEMENT address (#PCDATA)>
                <!ELEMETN email (#PCDATA)> ]>


XML;


?>
and one simple form: -
<html>
        <head>
                <title>My Address Book</title>
        </head>
        <body>
                <form action="addNewElement.php" method="post">
                        <div>
                                Group:<input type="text" size="20"
name="group"><br>
                                Name&nbsp;:<input type="text" size="20"
name="name"><br>
                                organization:<input type="text" size="20"
name="organization"> <br>
                                addresss:<input type="text" size="20"
name="ation"><br>
                                Email Address:<input type="text" size="20"
name="email">
                        </div>
                        <input type="submit" value="Submit">


                </form>
        </body>
</html>
But it gives lot of error : -
Warning: SimpleXMLElement::__construct() [function.--construct]: Entity:
line 9: parser error : DOCTYPE improperly terminated in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php on
line 5

Warning: SimpleXMLElement::__construct() [function.--construct]: <!ELEMETN
email (#PCDATA)> ]> in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php on
line 5

Warning: SimpleXMLElement::__construct() [function.--construct]: ^ in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php on
line 5

Warning: SimpleXMLElement::__construct() [function.--construct]: Entity:
line 9: parser error : Start tag expected, '<' not found in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php on
line 5

Warning: SimpleXMLElement::__construct() [function.--construct]: <!ELEMETN
email (#PCDATA)> ]> in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php on
line 5

Warning: SimpleXMLElement::__construct() [function.--construct]: ^ in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php on
line 5

Fatal error: Uncaught exception 'Exception' with message 'String could not
be parsed as XML' in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php:5
Stack trace: #0
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php(5):
SimpleXMLElement->__construct('?<?xml version=...') #1 {main} thrown in
/home/rakesh/public_html/Tutorials/XML_PHP/XML_PHP_BOOK/addNewElement.php on
line 5

please help me out..
onewaylife












Edward Kay wrote:
> 
> In that case you need to do some of your own research. Google is your
> friend.
> 
>> Hello Edward
>> Just i don't  now where to start.
>>
>>
>> Edward Kay wrote:
>> >
>> > Hello,
>> >
>> > You say that you are "unable to store the files in XML". Why is
>> this? Are
>> > you getting an error message or do you just not know where to start?
>> >
>> > Edward
>> >
>> >> Dear All
>> >>
>> >> I am novice in PHP & XML, while trying I am creating a small
>> application
>> >> i.e. Address Book.
>> >> In this I am using Apache2, PHP5 and XML no database is used.
>> I have FC5
>> >> machines. but I am unable to store the files in XML. If any one
>> >> share their
>> >> experience in this by providing Examples or tutorials etc...
>> >> So far I have found tutorial related to porting the information
>> >> of data from
>> >> MySQL to XML and then php with help of DOM.
>> >>
>> >> Thanks
>> >> onewaylife
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/PHP-and-XML-tf2692397.html#a7507917
>> >> Sent from the PHP - General mailing list archive at Nabble.com.
>> >>
>> >> --
>> >> 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
>> >
>> >
>> >
>>
>> --
>> View this message in context:
> http://www.nabble.com/PHP-and-XML-tf2692397.html#a7517770
> Sent from the PHP - General mailing list archive at Nabble.com.
> 
> --
> 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
> 
> 
> 
-- 
View this message in context: 
http://www.nabble.com/PHP-and-XML-tf2692397.html#a7555006
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
Sumeet wrote:

> Brad Fuller wrote:
> 
>> $command = "mysqldump -u $dbuser -p$dbpass $dbname | gzip >
>> $backupFile";
>> 
>> system($command);
>> 
>> 
> 
> what if system() has been disabled on the server?
> 

SELECT .... INTO OUTFILE 'file_name' export_options seems a useful
alternative.



Cheers
-- 
David Robley

"I haven't caught a fish all day!" Tom said, without debate.
Today is Sweetmorn, the 39th day of The Aftermath in the YOLD 3172. 

--- End Message ---

Reply via email to