php-general Digest 13 Jan 2005 14:27:54 -0000 Issue 3225
Topics (messages 206258 through 206281):
Re: delete part of array
206258 by: Tatang Widyanto
206259 by: Leif Gregory
206265 by: Jochem Maas
206266 by: Jochem Maas
206276 by: Matthew Fonda
206279 by: M. Sokolewicz
Re: sendmail crash
206260 by: Jochem Maas
Re: [PHP-WIN] HTML in PHP to a File
206261 by: Leif Gregory
Re: Data Enryption
206262 by: Jochem Maas
206267 by: Greg Donald
206268 by: Greg Donald
206274 by: Jochem Maas
206275 by: John Nichel
Identify which function called another
206263 by: Lars B. Jensen
206269 by: Lars B. Jensen
206270 by: Ben Ramsey
206272 by: Michael Sims
206273 by: Jochem Maas
206277 by: Lars B. Jensen
206278 by: Jochem Maas
Re: geographic search engine
206264 by: Richard Lynch
Downloading Images
206271 by: John Camp
PHP5 & FreeTDS
206280 by: Craig Donnelly
Re: PHP + MSSQL win32 / SOLVED
206281 by: Vincent DUPONT
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 ---
Sebastian wrote:
how do i delete keys from an array if it has no values?
eg, this:
[name] => Array
(
[0] => grape
[1] => apple
[2] =>
[3] => orange
[4] =>
[5] => cherry
)
to:
[name] => Array
(
[0] => grape
[1] => apple
[2] => orange
[3] => cherry
)
foreach ($name as $value) {
if ($value)
$buffer[] = $value;
}
$name = $buffer;
--- End Message ---
--- Begin Message ---
Hello Sebastian,
Wednesday, January 12, 2005, 5:22:20 PM, you wrote:
S> how do i delete keys from an array if it has no values?
S> eg, this:
array_merge($name);
Try it that way first. If not,
$name = array_merge($name);
But I think I remember the first way working for me.
Cheers,
Leif Gregory
--
TB Lists Moderator (and fellow registered end-user)
PCWize Editor / ICQ 216395 / PGP Key ID 0x7CD4926F
Web Site <http://www.PCWize.com>
--- End Message ---
--- Begin Message ---
Sebastian wrote:
how do i delete keys from an array if it has no values?
eg, this:
what does the value have to do with it??? other than that you want to
remove items where the value is 'empty'.
also 'no value' is vague, do you mean an empty string or do you mean NULL?
---
try the array_values() function, possibly in conjunction with
array_unique() depending on your requirements. look them up in the
manual, while your there read the rest of it as well.
---
I assume you know how to:
1. create an array
2. loop an array
3. check a variable's value is/isn't something in particular
4. assign a value to a variable.
combine these skills! (if you can answer no to any of the above
questions then you need to read the manual - its a good manual, people
have spent countless hours writing - show respect and use it!)
[name] => Array
(
[0] => grape
[1] => apple
[2] =>
[3] => orange
[4] =>
[5] => cherry
)
to:
[name] => Array
(
[0] => grape
[1] => apple
[2] => orange
[3] => cherry
)
--- End Message ---
--- Begin Message ---
Leif Gregory wrote:
Hello Sebastian,
Wednesday, January 12, 2005, 5:22:20 PM, you wrote:
S> how do i delete keys from an array if it has no values?
S> eg, this:
array_merge($name);
Try it that way first. If not,
read the manual entry first (see below) - and understand what the
function actually does - never just assume because its giving you the
result you want now that it will always work the way you expect.
$name = array_merge($name);
But I think I remember the first way working for me.
you think???
hit the manual: http://www.php.net/array_merge
(thats 30 chars to type in the addressbar of your favorite browser and
then you'd be sure)
probably array_merge() will do what he wants but there maybe
side-effects that will bite him in the ass later on, same goes for my
(previous) suggestion of array_values() as it happens <blush>.
a tip for those who don't already know:
php.net (and its mirrors (I usually use nl2.php.net)) have a great
search mechanism:
http://www.php.net/<function-name>
replace <function-name> with the name of function your interested in and
boom your right at the page you need! actually other keywords work as
well. for instance:
need to know more about arrays: http://www.php.net/array
or mysql http://www.php.net/mysql
or overloading http://www.php.net/overload
even when you don't know the exact keyword to use, your guess will often
get you where you want!
<BLATANT-PROMO>
nl2.php.net is the best php mirror out there *obviously*, nothing to do
with the fact that the guys that run it are friends of mine, or the fact
that they do such a great job at hosting alot of the sites I
build/run/own ;-) [www.nedlinux.nl: linux freaks with a lowlands twist]
</BLATANT-PROMO>
Cheers,
Leif Gregory
--- End Message ---
--- Begin Message ---
use the unset() function.
for ($i = 0; $i < count($array); $i++) {
if (empty($array[$i]) {
unset($array[$i]);
}
}
On Wed, 2005-01-12 at 16:22, Sebastian wrote:
> how do i delete keys from an array if it has no values?
> eg, this:
>
> [name] => Array
> (
> [0] => grape
> [1] => apple
> [2] =>
> [3] => orange
> [4] =>
> [5] => cherry
> )
>
> to:
>
> [name] => Array
> (
> [0] => grape
> [1] => apple
> [2] => orange
> [3] => cherry
> )
--
Regards,
Matthew Fonda
--- End Message ---
--- Begin Message ---
that only works for numerical indices.
However, if you're sure that neither null values, nor false values are
supposed to be present in the array, (that means, they MIGHT be, but
should be removed anyway; or just not be there at all,) then you could
try array_filter with no callback-argument :)
Another easy way would be:
foreach($array as $key=>$val) {
if($val === '') {
unset($array[$key]);
}
}
hope it helps
- Tul
Matthew Fonda wrote:
use the unset() function.
for ($i = 0; $i < count($array); $i++) {
if (empty($array[$i]) {
unset($array[$i]);
}
}
On Wed, 2005-01-12 at 16:22, Sebastian wrote:
how do i delete keys from an array if it has no values?
eg, this:
[name] => Array
(
[0] => grape
[1] => apple
[2] =>
[3] => orange
[4] =>
[5] => cherry
)
to:
[name] => Array
(
[0] => grape
[1] => apple
[2] => orange
[3] => cherry
)
--- End Message ---
--- Begin Message ---
Richard Lynch wrote:
> Michiel van der Blonk wrote:
>
...
>
> Is the above the ACTUAL email you are sending?
>
> Or merely a demonstrative sample?
>
> Cuz, like, if the email you are REALLY sending is *HUGE* then I'd not be
> surprised by the messages above...
>
Richard, what do you consider huge. I mean people (read: some of my
idiot co-worker) happily send 10Meg attachments via sendmail all day
long (okay so its not via PHP, but I sometimes use the phpMailer script
to send emails using PHP/sendmail and I have successfully done so with
10+ Megs of files attached).
is it possible he is hitting a PHP memory limit?
(I just tried googling the problem but the only thing that seemed
related that I came up with were Michiel posts :-S )
--- End Message ---
--- Begin Message ---
Hello MikeA,
Wednesday, January 12, 2005, 6:46:46 PM, you wrote:
M> <?php
M> echo "<P>The test is starting";
M> $echowrite = "echo ";
M> $echowrite."<P>This is the first line.";
M> echo "<P>You should have seen the first line by now.";
M> Did not work! Hey I'll try anything to get this to work! LOL
Not sure how to do the pagebreaks, but the reason your script didn't
do anything is that you never echo'd $echowrite.
$echowrite would have output:
************
echo
This is the first line.
************
Cheers,
Leif Gregory
--
TB Lists Moderator (and fellow registered end-user)
PCWize Editor / ICQ 216395 / PGP Key ID 0x7CD4926F
Web Site <http://www.PCWize.com>
--- End Message ---
--- Begin Message ---
Jason Wong wrote:
On Thursday 13 January 2005 01:55, Greg Donald wrote:
On Wed, 12 Jan 2005 18:09:08 +0100, Jochem Maas <[EMAIL PROTECTED]>
wrote:
I'm no expert on crypto (and never will be either! designing good crypto
is something best left to the very very very very best in terms of
computer science) but I think that the following function represents
very weak crypto -
Feel free to not use it then.. geez.
No offence, but as you are a ZCE, this might lead people that that function is
useful and might actually use it. Notwithstanding the fact that it is an
extremely weak encryption, OP please note that it is pointless to be
encrypting/storing/decrypting data all on the same machine. And if the data
to be encrypted is anywhere near sensitive then using weak encryption is
worse than no encryption (no encryption doesn't waste CPU cycles and doesn't
give a false sense of security).
thank god for your input, for a minute I thought I was (being) a
complete moron. :-)
(no disrespect to Zend, but ZCE _sounds_ a lot like MSCE and everyone
knows what thats worth ;-) - just a but of humour guys!)
actually I only noticed the ZCE after I posted; I just thought it a good
idea to give the 'noobs' a heads up regarding the fact thatgetting
encryption (& security) right is hard (well I think it it anyway)!
--- End Message ---
--- Begin Message ---
On Thu, 13 Jan 2005 03:37:29 +0100, Jochem Maas <[EMAIL PROTECTED]> wrote:
> (no disrespect to Zend, but ZCE _sounds_ a lot like MSCE and everyone
> knows what thats worth ;-) - just a but of humour guys!)
Yeah that's hilarious.
--
Greg Donald
Zend Certified Engineer
http://destiney.com/
--- End Message ---
--- Begin Message ---
On Thu, 13 Jan 2005 06:36:44 +0800, Jason Wong <[EMAIL PROTECTED]> wrote:
> No offence, but as you are a ZCE, this might lead people that that function is
> useful and might actually use it.
http://php.net/mcrypt in the comments section is where I found them.
I wouldn't protect the pentagon with them, but they've worked pretty
good for me more than a couple of times when mcrypt wasn't available.
If you don't want to use them then don't use them. I couldn't care less.
--
Greg Donald
Zend Certified Engineer
http://destiney.com/
--- End Message ---
--- Begin Message ---
Greg Donald wrote:
On Thu, 13 Jan 2005 03:37:29 +0100, Jochem Maas <[EMAIL PROTECTED]> wrote:
(no disrespect to Zend, but ZCE _sounds_ a lot like MSCE and everyone
knows what thats worth ;-) - just a but of humour guys!)
actually IMHO a ZCE is worth a heck of alot more than an MSCE (on paper
atleast). The only MSCE I would trust is one who did his/her damndest to
hide the fact that they were an MCSE :-)
Yeah that's hilarious.
well thats the great thing about humour, everyone is (should be?)
entitled to theirs!
like this:
<HUMOUR>
Greg, do you have a stomach ulcer? or are you just working on it?
</HUMOUR>
now cheer up Greg, before you really do get an ulcer!
--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
<snip>
(no disrespect to Zend, but ZCE _sounds_ a lot like MSCE and everyone
knows what thats worth ;-) - just a but of humour guys!)
<snip>
Oh yeah, I can hear all the Zend people laughing from here.
--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com
--- End Message ---
--- Begin Message ---
Is there any way, I from one function can identify which other function called
it, without parameter passing the name manually ?
In code, something like
<?php
function a() {
return c();
}
function b() {
return c();
}
function c() {
return 'I got called by'.$name_of_the_function_who_called_me;
}
echo b();
?>
where I would like to have function c identify if it was called by function a
or b
--
Lars B. Jensen, Internet Architect
CareerCross Japan
Japan's premier online career resource for english speaking professionals
http://www.careercross.com
--- End Message ---
--- Begin Message ---
Is there any way, I from one function can identify which other function called
it, without parameter passing the name manually ?
In code, something like
<?php
function a() {
return c();
}
function b() {
return c();
}
function c() {
return 'I got called by'.$name_of_the_function_who_called_me;
}
echo b();
?>
where I would like to have function c identify if it was called by function a
or b
--
Lars B. Jensen, Internet Architect
CareerCross Japan
Japan's premier online career resource for english speaking professionals
http://www.careercross.com
--- End Message ---
--- Begin Message ---
Lars B. Jensen wrote:
Is there any way, I from one function can identify which other function called it, without parameter passing the name manually ?
Please don't post twice in an hour if you haven't yet received your
answer. With that in mind, I have an answer for you. :-)
Use debug_backtrace():
http://www.php.net/debug-backtrace
Harry Fuecks has an excellent post on how to use debug_backtrace() here:
http://www.sitepoint.com/blog-post-view.php?id=157007
--
Ben Ramsey
Zend Certified Engineer
http://benramsey.com
--- End Message ---
--- Begin Message ---
Lars B. Jensen wrote:
> Is there any way, I from one function can identify which other
> function called it, without parameter passing the name manually ?
You can get this information from debug_backtrace()...
http://www.php.net/manual/en/function.debug-backtrace.php
--- End Message ---
--- Begin Message ---
Ben Ramsey wrote:
Lars B. Jensen wrote:
Is there any way, I from one function can identify which other
function called it, without parameter passing the name manually ?
I still question whether its correct to design a function which requires
this. I thought the idea of encapsulating code inside a function is that
its non-dependent/black-boxed.... still for every rule there is an
exception!
Please don't post twice in an hour if you haven't yet received your
answer. With that in mind, I have an answer for you. :-)
maybe Lars thought his post had disappeared into /dev/null, not
altogether strange considering the fluctuating time delays in posts
being sent out! then maybe he's an impatient s.o.b ;-)
Use debug_backtrace():
http://www.php.net/debug-backtrace
Harry Fuecks has an excellent post on how to use debug_backtrace() here:
http://www.sitepoint.com/blog-post-view.php?id=157007
He has a lot of those (excellent posts that is), but he is really giving
an example of debugging not writing code that relies on a debug_ function.
I don't think debug_backtrace() should be used like this, having said
that it will work - but I can only imagine that its a heavy function to
call (because it has to 'analyse' the stack in order to return alot of
info, nearly all of which is not needed in the case Lars presented)
--- End Message ---
--- Begin Message ---
Is there any way, I from one function can identify which other function
called it, without parameter passing the name manually ?
I still question whether its correct to design a function which requires
this. I thought the idea of encapsulating code inside a function is that
its non-dependent/black-boxed.... still for every rule there is an
exception!
Need it for my "identify why the hell this error occured, send email to the
admins with full debug, server variables, time, pop that into the
errorhandling database for cross referencing if it happened before".
Practically, yesterday, we spend a few hours tracing a special error
occuring extremely seldom and ended up making some crappy debugging on a
livesite.
Please don't post twice in an hour if you haven't yet received your
answer. With that in mind, I have an answer for you. :-)
maybe Lars thought his post had disappeared into /dev/null, not altogether
strange considering the fluctuating time delays in posts being sent out!
then maybe he's an impatient s.o.b ;-)
Or maybe Lars has multiple email accounts, and realized he was sending from
the wrong one forgetting he had authorized it beforehand.
/ Lars
--- End Message ---
--- Begin Message ---
Lars B. Jensen wrote:
Is there any way, I from one function can identify which other
function called it, without parameter passing the name manually ?
I still question whether its correct to design a function which
requires this. I thought the idea of encapsulating code inside a
function is that its non-dependent/black-boxed.... still for every
rule there is an exception!
Need it for my "identify why the hell this error occured, send email to
the admins with full debug, server variables, time, pop that into the
errorhandling database for cross referencing if it happened before".
damn good reason to use debug_backtrace() if you ask me :-)
Practically, yesterday, we spend a few hours tracing a special error
occuring extremely seldom and ended up making some crappy debugging on a
livesite.
Please don't post twice in an hour if you haven't yet received your
answer. With that in mind, I have an answer for you. :-)
maybe Lars thought his post had disappeared into /dev/null, not
altogether strange considering the fluctuating time delays in posts
being sent out! then maybe he's an impatient s.o.b ;-)
Or maybe Lars has multiple email accounts, and realized he was sending
from the wrong one forgetting he had authorized it beforehand.
I'm guessing Lars has multiple email accounts. ;-)
/ Lars
--- End Message ---
--- Begin Message ---
Brian Dunning wrote:
>>> I realized one day that at a distance of a hundred miles or less, I
>>> just
>>> didn't *CARE* about curvature of the earth, and replaced that trig
>>> with
>>> your basic Cartesian distance.
>
> True, but be aware that this is only true when all of your coordinates
> are in the same general latitude. For example, lines of longitude are
> much closer together in Montana than they are in Texas.
But we DON'T CARE!
I just want the closest Wendy's (as a real example of a HORRIBLE on-line
geographical search feature). I don't really care that that calculation
in miles is "off" by a mile or two, or 10, or 20, because the error will
be consistent within the data set.
I just want the CLOSEST whatever to country/postal XX/ABC-DEF.
You have to be at Santa's workshop or in that research complex down on the
South Pole for this to be a problem in the real world.
>>> If tomorrow the USPS creates zip code 60609, I can be
>>> pretty damn sure it's "close enough" to 60601 through 60608 and just
>>> average them to make up bogus long/lat. Sure, it's "wrong". It's
>>> also
>>> FREE and "close enough" for what I (and almost for sure you) are
>>> doing.
>
> As the purveyor of a zip code database, I can assure you that this is
> not at all true. In many cases it is, but in many cases, not. Example:
> Here in So Cal we have 8 new zip codes since last month where the
> nearest zip code numerically is over 25 miles away.
As a soon to be purveyor of a world-wide FREE postal code database, where
the OpenSource community, many of whom just happen to have those nifty GPS
devices, will be donating their hometown zip[s] I am not at all concerned
about this.
PS I also cross-check the city names. Frequently, you can eliminate all
but a couple records from your interpolation simply because they're in the
wrong city. Plus, sometimes you have to extend or shrink your range based
on the density of entries. But I've never had somebody complain because
the long/lat I interpolated was too far off. Been doing it for years now.
> But I hear what you're saying as far as "good enough" for this
> particular application.
EXACTLY!
I don't even care if a few entries are off by 25 miles for now. Somebody
will step up and fix them shortly. That's how Open Source works.
I've been using this succesfully for YEARS, so I know it works.
I just don't have the data for Canada, England, France, Australia, ...
that I want.
But there are a lot of common applications where it's good enough.
Store Locater
Gross-resolution tour-planning, such as a band on tour
Aggregate shipping/delivery planning
I'm sure there are a lot more applications that don't need the
fine-grained resolution of a MapQuest, but want this sort of feature to be
easily integrated to their site.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
I was able to successfully make a very simple http proxy - turns out the
php documentation has the code for this =] - but now I need a way to
display images. I figured the best way would be to download the images
to a temporary folder, then parse the html to point to the images on my
server instead. The problem is that I do not know how to download the
images.
Also if anyone has a link to a parsing script it would save a good
amount of time.
Thanks for any help.
--- End Message ---
--- Begin Message ---
I had FreeTDS and PHP 4.3.x working fine, then I upgraded my PHP
installation to PHP 5.0.3, now It isnt working.
On the page where I connect to the MSSQL server I get the following error:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to
server: 172.16.xx.xxx in /var/ftpusers/tarot/tarot/admin/sqltest.php on line
4
This worked fine before, and I tested it on another box which is also
running freeTDS with PHP 5.0.1 and it
connects fine. Anyone any Ideas??
Regards,
Craig
--- End Message ---
--- Begin Message ---
Hello,
I found the problem about my last message (see below).
This relates to a bug in 4.3.10 release with MSSQL extension
Bug #31372
I downgraded to PHP 4.3.8 and the problem was solved.
Thank you for your attention and replies
Vincent
-----Original Message-----
From: Vincent DUPONT
Sent: mercredi 12 janvier 2005 21:54
To: [email protected]
Subject: [PHP] PHP + MSSQL win32
Hi
I try to use PHP with MSSQL on a WINXP station.
Usually, on win32 systems this works very well, but today I can't
understand the problem.
I can connect and execute SELECT statements
When I try to INSERT , DELETE or UPDATE a record, I have a PHP ERROR,
and a MSSQL error "code 15457" in the mssql logs
The insert executes, but I would like not to have the php error...
This seem to be a problem with grants or permissions, but I can't find
where. Even if I log with the 'sa' account I have the error.
I use PHP 4.3.10 and MSSQL2000 on winXP pro
Any tip would be nice.
Moreover, I have found a ini file parameter that is not documented :
mssql.datetimeconvert=Off
Do you know what does this mean??
Thank you
Vincent
--- End Message ---