php-general Digest 22 Jan 2005 12:30:54 -0000 Issue 3242
Topics (messages 207014 through 207038):
Re: Using List() and a do-while loop with MySQL results.
207014 by: Jason Wong
207019 by: Chris
207020 by: Phillip S. Baker
Re: multiple sessions on same server/domain
207015 by: Jordi Canals
suspicious? maybe spam? what?
207016 by: Chris W. Parker
Re: Notice:Use of undefined constant
207017 by: Tamas Hegedus
207018 by: Jason Wong
Re: help with nl2br
207021 by: Samuel DeVore
207023 by: Karthik
207026 by: Jochem Maas
Classes and parents.
207022 by: Dmitry
207029 by: Matthew Fonda
207030 by: Jochem Maas
207031 by: Jochem Maas
207035 by: Dmitry
Re: nl2br misprint
207024 by: Bret Hughes
oops! [was]:Storing key values in an array^%$&
207025 by: Jochem Maas
Re: too slow to unset big array (after mem fragment)
207027 by: Xuefer Tinys
Re: control REMOTE_ADDR header
207028 by: Alawi Albaity
207032 by: Greg Donald
PHP.ini setup, config, installation & recognition?
207033 by: Joseph E. Maxwell
207036 by: David Robley
gzip functions and error
207034 by: Dmitry
Preg_match----------help
207037 by: Chandana Bandara
end of array
207038 by: Jeffery Fernandez
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:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On Saturday 22 January 2005 08:11, Jason Wong wrote:
> On Saturday 22 January 2005 08:02, Phillip S. Baker wrote:
> > I am pulling records from a MySQL DB.
> > I am walking through the array using the whole.
>
> You do realise that doing this ...
>
> > if ( $row = mysql_fetch_assoc($result)) {
> > do {
> > // Some stuff
> > } while ( $row = mysql_fetch_assoc($result));
> > }
>
> ... effectively discards the first result of any resultset that you get?
> Unless that really is your intention then simply use a while-loop. If there
> aren't any results nothing in the while-loop will be executed (which means
> there is no need for the IF).
Sorry, no it doesn't. But it's much clumsier than simply using a while-loop.
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> ------------------------------------------
> Search the list archives before you post
> http://marc.theaimsgroup.com/?l=php-general
> ------------------------------------------
> New Year Resolution: Ignore top posted posts
--- End Message ---
--- Begin Message ---
Excerpt from http://www.php.net/list
"*Note: * *list()* only works on numerical arrays and assumes the
numerical indices start at 0."
So the best way , in my opinion, to achieve this effect would be:
while(list($id, $someinfo) = mysql_fetch_row($result))
{
// Some stuff
}
Chris
Phillip S. Baker wrote:
Greetings all,
I am pulling records from a MySQL DB.
I am walking through the array using the whole.
if ( $row = mysql_fetch_assoc($result)) {
do {
// Some stuff
} while ( $row = mysql_fetch_assoc($result));
}
What I am wondering is if there is something I can do like.
if ( list ($id, $someinfo) = mysql_fetch_assoc($result)) {
do {
// Some stuff
} while ( list ($id, $someinfo) = mysql_fetch_assoc($result));
}
When I tried something like that
The variables where not populated.
Is there something I am doing wrong, or is this just something that cannot
be done (or is bad programming practice??)
Thanks.
--
Blessed Be
Phillip
--- End Message ---
--- Begin Message ---
Thanks.
That was the problem. I switched it to FetchRow and got what I was looking
for.
--
Blessed Be
Phillip
"Chris" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Excerpt from http://www.php.net/list
>
> "*Note: * *list()* only works on numerical arrays and assumes the
> numerical indices start at 0."
>
> So the best way , in my opinion, to achieve this effect would be:
>
>
> while(list($id, $someinfo) = mysql_fetch_row($result))
> {
> // Some stuff
> }
>
> Chris
>
> Phillip S. Baker wrote:
>
> >Greetings all,
> >
> >I am pulling records from a MySQL DB.
> >I am walking through the array using the whole.
> >if ( $row = mysql_fetch_assoc($result)) {
> > do {
> > // Some stuff
> > } while ( $row = mysql_fetch_assoc($result));
> >}
> >
> >What I am wondering is if there is something I can do like.
> >
> >if ( list ($id, $someinfo) = mysql_fetch_assoc($result)) {
> > do {
> > // Some stuff
> > } while ( list ($id, $someinfo) = mysql_fetch_assoc($result));
> >}
> >
> >When I tried something like that
> >The variables where not populated.
> >Is there something I am doing wrong, or is this just something that
cannot
> >be done (or is bad programming practice??)
> >
> >Thanks.
> >
> >--
> >Blessed Be
> >
> >Phillip
> >
> >
> >
--- End Message ---
--- Begin Message ---
On Fri, 21 Jan 2005 09:43:38 -0800 (PST), Richard Lynch <[EMAIL PROTECTED]>
wrote:
> Thus my point remains:
> On a shared server, I don't need to resort to calling this function to
> hijack your Cookie/session. PHP can read the raw session files. I can
> write a PHP script to read the raw session files, regardless of what
> directory the Cookie is set to use to store/retrieve the Cookie whose
> purpose is to identify those files.
>
> This is not something you can "fix" in any real-world scenario where it
> matters.
Of course you can fix it! You can change your sessions handler and
save your session data in a database. For that you can use the
session_set_save_handler().
Best regards,
Jordi.
--- End Message ---
--- Begin Message ---
<rant>
Will whoever is causing "[suspicious - maybe spam]" to appear in the
subject of the PHP emails PLEASE WHITELIST THE PHP LIST. Ugh.. it's so
annoying.
</rant>
Chris.
--- End Message ---
--- Begin Message ---
In a file, which is included into all my scripts, I defined constants
(for MySQL access). PHP claims these constants as undifined constants,
however, if I let them print out they have the right values
(HOST='localhost'; NOT: HOST='HOST').
Where do you print them out? In the file in which they're defined or somewhere
else?
I was wrong. In my test scritp I do not include any other file, just
define the constants, and print them out.
This suggests that your file containing the constants definitions was not
included. Which means you're not going to be able to connect to mysql (unless
by some fluke that your host happens to be 'HOST', etc).
This could not happen, since I did not inserted any other file in my
test script.
===========
But now I run the test script on my local machine without any notice.
My php -v:
PHP 4.3.2 (cgi), Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
The script:
---------------
<?php
//-- Ez a teszt
define( HOST, 'localhost');
define( USER, 'hae');
define( PWD, 'hae');
define( DB, 'haetest');
echo 'Host/User/db: ' . HOST . USER . DB;
exit;
/*-- Ez az eredeti
define( HOST, 'localhost');
define( USER, 'h');
define( PWD, 'h');
define( DB, 'hae');
*/
$link = mysql_connect( HOST, USER, PWD);
mysql_select_db( DB);
...
Thanks,
Tamas
--
Tamas Hegedus, Research Fellow | phone: (1) 480-301-6041
Mayo Clinic Scottsdale | fax: (1) 480-301-7017
13000 E. Shea Blvd | mailto:[EMAIL PROTECTED]
Scottsdale, AZ, 85259 | http://hegedus.brumart.org
--- End Message ---
--- Begin Message ---
On Saturday 22 January 2005 08:28, Tamas Hegedus wrote:
> define( HOST, 'localhost');
define('HOST', 'localhost');
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts
--- End Message ---
--- Begin Message ---
You might check out http://photomatt.net/scripts/autop
"Call this function on the text you want to convert. Think of this
code like nl2br on steroids. This is basically a cross-platform set of
regular expressions that takes text formatted only by newlines and
transforms it into text properly marked up with paragraph and line
break tags. The line break part can also be turned off if you want."
It's really clean and useful
Sam D
> [snip]
> some text copy<br />
> <br />
> Some more copy<br />
>
> What I want instead is
> <p>Some text copy</p>
>
> <p>some more text copy</p>
> [/snip]
--- End Message ---
--- Begin Message ---
Hey,
I would just suggest that you "Explode" the data based on \n and
then "walk" through it adding <p> </p> and <br /> tags as necessary..
shouldn't be too diffcult.
hth
-K
On Fri, 21 Jan 2005 14:19:38 -0800, Phillip S. Baker
<[EMAIL PROTECTED]> wrote:
> Greetings all,
>
> Due to style sheet stuff I need to modify the nl2br (IE create or use a
> different function).
>
> I am pulling data from a database and using nl2br, which does the standard.
>
> some text copy<br />
> <br />
> Some more copy<br />
>
> What I want instead is
> <p>Some text copy</p>
>
> <p>some more text copy</p>
>
> Again this is because of css and the designer I am workign with. Is there a
> built in function that can do something like this or another function out
> there. So far I cannot see anything. Or is there a way to view the coding of
> the nl2br function so I can create a new function modifying how it does it.
>
> Just asking so I do not have to create something from scratch.
> Thanks.
--- End Message ---
--- Begin Message ---
Phillip S. Baker wrote:
Greetings all,
Due to style sheet stuff I need to modify the nl2br (IE create or use a
different function).
I am pulling data from a database and using nl2br, which does the standard.
...........
.html:
<div class="ParaFakeOrWhatEver">
some text copy<br />
<br />
Some more copy<br />
</div>
...........
.css:
.ParaFakeOrWhatEver
{
color: #c0c0c0;
line-height: 1.5em;
margin: 2em;
}
What I want instead is
<p>Some text copy</p>
<p>some more text copy</p>
Again this is because of css and the designer I am working with. Is there a
maybe something as trivial as a extra few pixels between paragraphs may
be time better spent on other parts of the system? this is web not
print. and if 'designers' would get that then we wouldn't have to live
in <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="5"><img src="/images/spacer.gif" width="1"
height="1"></td>
</tr>
<tr>
<td valign="top"><img src="/images/header/yyy.gif"
width="192" height="61"></td>
<td><img src="/images/spacer.gif" width="1" height="1"></td>
<td valign="top"><a href="target="_blank"><img
src="/images/header/xxx.gif" width="66" height="61" style="border:
none;"></a></td>
<td><img src="/images/spacer.gif" width="1" height="1"></td>
<td width="100%"> </td>
</tr>
</table> hell any longer, clean simple layout thats not pushed by
print media expectations.
built in function that can do something like this or another function out
there. So far I cannot see anything. Or is there a way to view the coding of
the nl2br function so I can create a new function modifying how it does it.
I'm guess that if you could program C that you would have already
downloaded the source and started hacking... so the answer is. yes and
probably not at this point in time, my utmost apologies if I am wrong!
Just asking so I do not have to create something from scratch.
Thanks.
preg_replace();
--
Blessed Be
Phillip
--- End Message ---
--- Begin Message ---
Greetings.
If i run this code (php5):
------------------------------------------
class a {
function say() { echo "A"; }
function run() { $this->say(); }
}
class b extends a {
function say() { echo "B"; }
function run() { parent::run(); }
}
$obj = new b;
$obj->run();
---------------------------------------
I will get "B", but how i may get "A"?
--- End Message ---
--- Begin Message ---
the run function in b overrides the run function in a, thats why it
echo's "B"
On Fri, 2005-01-21 at 18:37, Dmitry wrote:
> Greetings.
>
> If i run this code (php5):
> ------------------------------------------
> class a {
> function say() { echo "A"; }
> function run() { $this->say(); }
> }
> class b extends a {
> function say() { echo "B"; }
> function run() { parent::run(); }
> }
>
> $obj = new b;
> $obj->run();
> ---------------------------------------
>
> I will get "B", but how i may get "A"?
--
Regards,
Matthew Fonda
--- End Message ---
--- Begin Message ---
Dmitry wrote:
Greetings.
If i run this code (php5):
------------------------------------------
class a {
function say() { echo "A"; }
function run() { $this->say(); }
}
class b extends a {
function say() { echo "B"; }
function run() { parent::run(); }
}
$obj = new b;
$obj->run();
---------------------------------------
I will get "B", but how i may get "A"?
php -r '
class a {
function __construct($speak = false) { $this->run($speak); }
protected function say($speak) { if($speak) { echo "A"; } }
public function run($speak = true) { $this->say($speak); }
}
class b extends a
{
private $base;
function __construct($speak = false)
{
$this->base = new A($speak);
if ($speak) {
$this->run();
} else {
$this->base->run();
}
}
protected function say($speak)
{
if($speak) {
echo "B";
}else {
parent::say(!$speak);
}
}
public function run($speak = true)
{
$this->say($speak);
}
}
$obj = new b;$obj->run(false); echo "or try out reflection?\n"'
AA
or try out reflection?
--- End Message ---
--- Begin Message ---
had to better myself...
Jochem Maas wrote:
Dmitry wrote:
Greetings.
If i run this code (php5):
------------------------------------------
class a {
function say() { echo "A"; }
function run() { $this->say(); }
}
class b extends a {
function say() { echo "B"; }
function run() { parent::run(); }
}
$obj = new b;
$obj->run();
---------------------------------------
I will get "B", but how i may get "A"?
php -r '
class a { private $A;
function __construct($speak = false ){$this->A="A"; $this->run($speak); }
protected function say($speak) { if($speak) { echo $this->A; } }
public function run($speak = true) { $this->say($speak); }
}
class b extends a {
private $base;
function __construct($speak = false) {
parent::__construct();$this->base = new A($speak); if ($speak) {
$this->run(); } else { $this->base->run(); } }
protected function say($speak) { if($speak) { echo "B"; }else {
parent::say(!$speak); } }
public function run($speak = true) { $this->say($speak); }
}
$obj = new b;$obj->run(false);'
AAA
--- End Message ---
--- Begin Message ---
Thanks,
but I think that this code more easy.
class a {
function say() { echo "A"; }
function run() { $this->say(); }
}
class b {
function say() { echo "B"; }
function run() {
$a = new a;
$a->run();
}
}
$obj = new b;
$obj->run();
--- End Message ---
--- Begin Message ---
On Fri, 2005-01-21 at 17:52, Jason Wong wrote:
> On Saturday 22 January 2005 07:36, Scott DeMers wrote:
> > From the function page on php.net (
> > http://us4.php.net/manual/en/function.nl2br.php ):
> >
> > "Starting with PHP 4.0.5, nl2br() is now XHTML compliant. All versions
> > before 4.0.5 will return string with '<br>' inserted before newlines
> > instead of '<br />'."
> >
> > Is this a misprint, ot does the revised function actually do this?
> > According to the w3c, "<br />' is compliant, while "<br>" is not; see
> > http://www.w3.org/TR/xhtml1/.
>
> Versions before 4.0.5 returns "<br>"
> Versions after 4.0.5 returns "<br />"
>
Logic error. what about the case of version = 4.0.5. :)
No need to reply. I get it but could not resist the dig.
Bret
--- End Message ---
--- Begin Message ---
Dear Todd,
to avoid the rants of the likes below in future, please post your actual
code ;-)
Todd Cary wrote:
Jochem -
The problem is the sort()! I did not realize that it replaces the key
just for the sake of history your __complete__ O(*&^&*^$ original post:
=========
I am using an array to populate a drop-down and I would like to have the
same value in the key as the value. Using the following, the key is
0,1,2,3...etc. How can I correct that?
$file_list = array();
$dir = opendir($doc_dir);
while (false !== ($file = readdir($dir))) {
if (($file != ".") && ($file != ".."))
$file_list[$file] = $file; <---------------<<<<<
}
Todd
http://nl2.php.net/sort
--- End Message ---
--- Begin Message ---
On Fri, 21 Jan 2005 11:49:30 -0800 (PST), Richard Lynch <[EMAIL PROTECTED]>
wrote:
>
> Perhaps you could store all data with an index of time rounded off to
> minutes (hours, whatever).
>
> Example:
>
> <?php
> //15 minutes -- Change larger/smaller for more/less frequent purges
> $purge_time = 60 * 15
> $now = time();
>
> //purge old data:
> $old = floor($now - $purge_time) / $purge_time);
> unset($tracker[$old]);
>
> //store incoming data:
> $current = floor($now / $purge_time);
> $tracker[$current][...whatever you use now...] = ...data...;
> ?>
looks good for GC, but seems bad for "in USE"
whenever there's an incoming new data which is not set in
$tracker[$current][...whatever you use now...], i have to go through
back all chunks of $tracker[] to archive "1hour tracking" effect
for $tracker[...]['site.view'][$siteid], only the first click is new,
cos they click same site
but for $tracker[...]['thread.view'][$threadid], almost all clicks is
new, cos they don't read same thread
each time i roll chunk, current online users make
$tracker[...]['site.view'][$siteid] is double from chunk[new-1] to
chunk[new]
too freq make it too many copies
but i'd guess it's ok for 'thread.view', "cos they don't read same
thread", no double
imagine if u guys write ip tracked(1 ip 1 view) counter, how will u
write the daemon?
database is slow imho
> If you make the $purge_time *TOO* small, smaller than the frequency with
> which the loop runs, then old data will get "missed" and never purged.
no problem, i can do
$expred = floor((time() - 1hour)/$pure_time);
reset(..)
while(list ... each())
break if $key >= not expired
--- End Message ---
--- Begin Message ---
I Want to control some privacy is there class to help me do that ?
On Sun, 16 Jan 2005 19:59:30 -0800 (PST), Richard Lynch <[EMAIL PROTECTED]>
wrote:
> Alawi Albaity wrote:
> > how can I can send http request with my chosen REMOTE_ADDR is there a
> > class
> > to do that or method in php ?
>
> I'm not 100% certain, but I think REMOTE_ADDR comes from data embedded in
> the TCP/IP info...
>
> So, basically, you'd have to seriously hack things to forge your return IP
> address... And then the data would go to somebody else. *WHY* do you
> think you need this?...
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
>
--
Alawi Albaity
Jeddah - KSA
Mobile : +966506660442
--- End Message ---
--- Begin Message ---
On Sat, 22 Jan 2005 06:52:37 +0300, Alawi Albaity <[EMAIL PROTECTED]> wrote:
> I Want to control some privacy is there class to help me do that ?
http://www.anonymizer.com/
--
Greg Donald
Zend Certified Engineer
http://destiney.com/
--- End Message ---
--- Begin Message ---
Hello,
I am setting up a program that requires allow_call_time_pass_reference to be
enabled. I've set allow_call_time_pass_reference = ON in the
/usr/local/etc/php.ini file
grep -n allow_call_time_pass_reference /usr/local/etc/php.ini
70: - allow_call_time_pass_reference = 1 [Code cleanliness]
167:allow_call_time_pass_reference = 1
But the program still calls for the option to be enabled. So I have run a test
file with the ini_get function, the code below.
------code-------
<html>
<head>
<title>Test Page</title>
</head>
<body bgcolor=#FFFFFF text=#000000>
<?php echo ini_get('allow_call_time_pass_reference'); ?>
</body>
</html>
----end code-----
Output page ==> blank
/usr/local/etc/php.ini has permissions set to 444 and listed in phpinfo.php
Suggestions?
Thanks!
--- End Message ---
--- Begin Message ---
On Saturday 22 January 2005 18:08, Joseph E. Maxwell wrote:
> Hello,
>
> I am setting up a program that requires allow_call_time_pass_reference to
> be enabled. I've set allow_call_time_pass_reference = ON in the
> /usr/local/etc/php.ini file
>
> grep -n allow_call_time_pass_reference /usr/local/etc/php.ini
> 70: - allow_call_time_pass_reference = 1 [Code cleanliness]
> 167:allow_call_time_pass_reference = 1
>
> But the program still calls for the option to be enabled. So I have run a
> test file with the ini_get function, the code below. ------code-------
> <html>
> <head>
> <title>Test Page</title>
> </head>
> <body bgcolor=#FFFFFF text=#000000>
> <?php echo ini_get('allow_call_time_pass_reference'); ?>
> </body>
> </html>
> ----end code-----
>
> Output page ==> blank
>
> /usr/local/etc/php.ini has permissions set to 444 and listed in
> phpinfo.php
>
> Suggestions?
You don't say whether you restarted apache; this is required to read and
utilise the changes to php.ini.
--
David Robley
That does not compute.
--- End Message ---
--- Begin Message ---
Hello!
How disable error messages when i send incorrect data into gzip* "extract"
functions, such as gzinflate or gzuncompress?
For example:
function _pack($data) {
$data = serialize($data);
$data = gzdeflate($data,9);
$data = base64_encode($data);
$data = urlencode($data);
return $data;
} # _pack()
function _unpack($data) {
$data = urldecode($data);
$data = base64_decode($data);
$data = gzinflate($data);
$data = unserialize($data);
return $data;
} # _unpack()
$s = _pack("123"); // K7YytlIyNDJWsgYA
$s = _unpack("K7YytlIyNDJWsgYA"); // 123
$s = _unpack("123"); // Warning: gzinflate() [function.gzinflate]: data
error
How disable this warnings? error_reporting(0) or @ operators does not help
me.
But I dont want use error_handler functions.
Thanks.
--- End Message ---
--- Begin Message ---
hi ,
using preg_match , how can i match "<", "_" , ">" " - " such special characters
in a sentence ???
Eg:
Strings are like this,
1.Ahgrwgsgd dfjb yuhh dfh <ABCD AFGHFDc GHJGKJ ------------------ here i want
to match <ABCD
2.AFRYRGH vhGHJGB <ASD_ASD_DER> GHJGJ kjHGKJGK ---------- here i want to
match <ASD_ASD_DER>
3.GHHTGH GHJK <BO-CA JKJ JLKL ---------------here i want to match <BO-CA
what is the most suitable way to match those data ? plz guide me ,
Thanx in advance,
chandana
--- End Message ---
--- Begin Message ---
Hi all,
I have a foreach loop on an array and within that loop I need to find if
the array has reached the last pointer. I have tried
if (next($row))
{
}
but that advances the pointer. Any tips on finding out if the array
pointer has reached the last element ?
cheers,
Jeffery
--- End Message ---