php-general Digest 24 Jan 2005 01:41:17 -0000 Issue 3245
Topics (messages 207077 through 207104):
sorting associative array
207077 by: Jeffery Fernandez
207082 by: Jochem Maas
207083 by: Kurt Yoder
207098 by: Jeffery Fernandez
Re: Why no type hints for built-in types?
207078 by: Terje Sletteb�
207080 by: Jochem Maas
Re: Why is access and visibility mixed up in PHP?
207079 by: Jochem Maas
207097 by: Terje Sletteb�
Re: Xemacs indentation for php
207081 by: dayton.brooklyn.cuny.edu
Re: Is this even possible?
207084 by: Mikey
Lost connection to mysql db. Plus I could use some help
207085 by: Jimbob
array search
207086 by: Malcolm
207087 by: Jochem Maas
207088 by: john.johnallsopp.co.uk
207089 by: Malcolm
207090 by: Ben Edwards
207091 by: M. Sokolewicz
207092 by: Malcolm
[email protected]
207093 by: Ralph Frost
Jason
207094 by: Tamas Hegedus
Attempting to use 'passthru' or 'exec' function
207095 by: Andre Dubuc
207096 by: Mikey
207104 by: Jason Wong
skip file_get_contents
207099 by: Ahmed Abdel-Aliem
Re: Session errors when uploaded to host
207100 by: Jerry Kita
207103 by: Tim Burgan
sessions
207101 by: Sam Webb
PHP Application server
207102 by: Devraj Mukherjee
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 ---
I have the following multi-dimentional array and I want to sort it by
the "score" key value
print_r($data);
Array
(
[0] => Array
(
[video_id] => 71
[old_id] => 7854
[title] => When the fire comes
[video_copies] => 1
[running_time] => 48
[date_published] => 06/02
[place_published] => Australia
[abstract] => ABC TV Gives details on many aspects of bushfires:
.......................
[library_medium_id] => 5
[library_type] => 4
[score] => 6.3310546875
)
[1] => Array
(
[video_id] => 9
[old_id] => 7792
[title] => Fire awareness
[video_copies] => 1
[running_time] => 15
[date_published] =>
[place_published] => Victoria
[abstract] => Safetycare Australia A general video lookin.........
[library_medium_id] => 5
[library_type] => 4
[score] => 3.1997931003571
)
)
any ideas. Thanks
Jeffery
--- End Message ---
--- Begin Message ---
Jeffery Fernandez wrote:
I have the following multi-dimentional array and I want to sort it by
the "score" key value
...
any ideas. Thanks
A long time ago I had this problem, came up with the following class (based
on
someone else's stuff that I found in the comments section of the php manual) to
handle it for me. its probably a rubbish way of doing it (look forward to
some clever bar steward showing us how do it in 3 lines. :-) ) - there are
usage examples
at the bottom:
<?php
/**
* MDASort.class.php :: simple interface to sort a mutlidimensional array
*
* We often have arrays of arrays where the sub-arrays are rows of data
* (either created or extracted from a database) - this class allows us to
* easily sort arrays in the base container array by any number of keys found
* in the sub-arrays. be aware that it is assumed that the array keys found in
the
* sub arrays are associative. Also maybe the _sortcmp method could be enhanced
to
* allow arbitrary levels of arrays to be sorted: by calling sort() on a level
* N array also the sortKeys contents would then have to be checked to see if
* they applied to the current (sub-)array
*
* @author Some guy on PHP comment board. <http://www.php.net/usort\>
* @author Jochem Maas <[EMAIL PROTECTED]>
*
* $Id: MDASort.class.php,v 1.1 2004/08/03 13:38:37 jochem Exp $
*
*/
/**
* This file and its contents is not copyrighted;
* The contents are free to be used by anybody under any conditions.
*/
class MDASort {
private $dataArray; //the array we want to sort.
private $sortKeys; //the order in which we want the array to be sorted.
function __construct()
{
if ($cnt = func_num_args()) {
$args = func_get_args();
if (isset($args[0])) {
$this->setData($args[0]);
}
if (isset($args[1])) {
$this->setSortKeys($args[1]);
}
if (isset($args[2]) && $args[2] === true) {
$this->sort();
}
}
}
function _sortcmp($a, $b, $i=0)
{
$r = strnatcmp($a[$this->sortKeys[$i][0]],$b[$this->sortKeys[$i][0]]);
if ($this->sortKeys[$i][1] == "DESC") $r = $r * -1;
if($r==0) {
$i++;
if ($this->sortKeys[$i]) $r = $this->_sortcmp($a, $b, $i);
}
return $r;
}
function sort()
{
if(count($this->sortKeys)) {
usort($this->dataArray, array($this,"_sortcmp"));
}
}
function setData($dataArray = array())
{
$this->dataArray = $dataArray;
}
function setSortKeys($sortKeys = array())
{
$this->sortKeys = $sortKeys;
}
function getData()
{
return $this->dataArray;
}
function getSortKeys()
{
return $this->sortKeys;
}
}
/* example of usage */
/*
$sorter = new MDASort;
$sorter->setData( array(
array("name" => "hank", "headsize" => "small", "age" => 32),
array("name" => "sade", "headsize" => "petit", "age" => 36),
array("name" => "hank", "headsize" => "large", "age" => 33),
array("name" => "sade", "headsize" => "large", "age" => 32),
array("name" => "john", "headsize" => "large", "age" => 32),
array("name" => "hank", "headsize" => "small", "age" => 36),
array("name" => "hank", "headsize" => "small", "age" => 40)
));
$sorter->setSortKeys( array(
array('name','ASC'),
array('headsize','DESC'),
array('age','ASC'),
));
$sorter->sort();
$sortedArray = $sorter->getData();
*/
/* 2nd example of usage */
/*
$data = array(
array("name" => "hank", "headsize" => "small", "age" => 32),
array("name" => "sade", "headsize" => "petit", "age" => 36),
array("name" => "hank", "headsize" => "large", "age" => 33),
array("name" => "sade", "headsize" => "large", "age" => 32),
array("name" => "john", "headsize" => "large", "age" => 32),
array("name" => "hank", "headsize" => "small", "age" => 36),
array("name" => "hank", "headsize" => "small", "age" => 40)
);
$sort = array(
array('name','ASC'),
array('headsize','DESC'),
array('age','ASC'),
);
$sorter = new MDASort($data, $sort);
$sorter->sort();
$sortedArray = $sorter->getData();
*/
/* 3rd example of usage */
/*
$data = array(
array("name" => "hank", "headsize" => "small", "age" => 32),
array("name" => "sade", "headsize" => "petit", "age" => 36),
array("name" => "hank", "headsize" => "large", "age" => 33),
array("name" => "sade", "headsize" => "large", "age" => 32),
array("name" => "john", "headsize" => "large", "age" => 32),
array("name" => "hank", "headsize" => "small", "age" => 36),
array("name" => "hank", "headsize" => "small", "age" => 40)
);
$sort = array(
array('name','ASC'),
array('headsize','DESC'),
array('age','ASC'),
);
$sorter = new MDASort($data, $sort, true); // auto sort
$sortedArray = $sorter->getData();
*/
Jeffery
--- End Message ---
--- Begin Message ---
Use usort (stealing from php docs):
function cmp($a['score'], $b['score'])
{
if ($a['score'] == $b['score']) {
return 0;
}
return ($a['score'] < $b['score']) ? -1 : 1;
}
$data = array(...);
usort($data, "cmp");
On Jan 23, 2005, at 8:39 AM, Jeffery Fernandez wrote:
I have the following multi-dimentional array and I want to sort it by
the "score" key value
print_r($data);
Array
(
[0] => Array
(
[video_id] => 71
[old_id] => 7854
[title] => When the fire comes
[video_copies] => 1
[running_time] => 48
[date_published] => 06/02
[place_published] => Australia
[abstract] => ABC TV Gives details on many aspects of
bushfires: .......................
[library_medium_id] => 5
[library_type] => 4
[score] => 6.3310546875
)
[1] => Array
(
[video_id] => 9
[old_id] => 7792
[title] => Fire awareness
[video_copies] => 1
[running_time] => 15
[date_published] => [place_published] => Victoria
[abstract] => Safetycare Australia A general video
lookin.........
[library_medium_id] => 5
[library_type] => 4
[score] => 3.1997931003571
)
)
any ideas. Thanks
Jeffery
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Kurt Yoder
http://yoderhome.com
--- End Message ---
--- Begin Message ---
Kurt Yoder wrote:
Use usort (stealing from php docs):
function cmp($a['score'], $b['score'])
{
if ($a['score'] == $b['score']) {
return 0;
}
return ($a['score'] < $b['score']) ? -1 : 1;
}
$data = array(...);
usort($data, "cmp");
This won't work for me as I have 500+ records to sort based on the score
key.. looking at jochem's class now. Thanks
Jeffery
On Jan 23, 2005, at 8:39 AM, Jeffery Fernandez wrote:
I have the following multi-dimentional array and I want to sort it by
the "score" key value
print_r($data);
Array
(
[0] => Array
(
[video_id] => 71
[old_id] => 7854
[title] => When the fire comes
[video_copies] => 1
[running_time] => 48
[date_published] => 06/02
[place_published] => Australia
[abstract] => ABC TV Gives details on many aspects of
bushfires: .......................
[library_medium_id] => 5
[library_type] => 4
[score] => 6.3310546875
)
[1] => Array
(
[video_id] => 9
[old_id] => 7792
[title] => Fire awareness
[video_copies] => 1
[running_time] => 15
[date_published] => [place_published] => Victoria
[abstract] => Safetycare Australia A general video
lookin.........
[library_medium_id] => 5
[library_type] => 4
[score] => 3.1997931003571
)
)
any ideas. Thanks
Jeffery
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Kurt Yoder
http://yoderhome.com
--- End Message ---
--- Begin Message ---
>From: "Matthew Weier O'Phinney" <[EMAIL PROTECTED]>
> * Terje Sletteb� <[EMAIL PROTECTED]>:
> > In PHP5, you can provide "type hints" for functions, like this:
> >
> > class Person {...}
> >
> > function f(Person $p)
> > {
> > ...
> > }
> >
> > Since this is optional static typing for objects, why not make the same
> > capability available for all types, built-in types included?
> >
> > I come from a background with generally static and strong typing (C++,
> > Java), and having worked with PHP a couple of years, I've quite a few
times
> > got bitten by stupid bugs that could have been caught by static typing,
such
> > as passing an empty string - which gets converted to 0 in an arithmetic
> > context, when the function was supposed to receive a number, or some
such,
> > and no error is reported. These bugs can be hard to find.
>
> This is where the === and !== comparison operators can come in handy, as
> they compare not only the values but the types. I often need to do this
> when checking for zeroes.
Hm, good point. However, this essentially means you have to do "manually"
what the compiler could have done. For example:
function f($a,$b,$c)
{
assert("is_int(\$a)");
assert("is_string(\$b)");
assert("is_array(\$c)");
// Actual function content here
}
At one time, I actually started to do this, but in the end, I found it
cluttered more than it helped; all those extra lines for each parameter:
clearly, the language worked against me on this. On the other hand, had I
been able to do this:
function f(int $a,string $b,array $c)
{
// Actual function content here
}
then it would have been just fine. It also works as documentation,
specifying what the function expects (and might also specify what it
returns).
> > This has been suggested in a few Q & A's at Zend, such as this one:
> > http://www.zend.com/expert_qa/qas.php?id=104&single=1
> >
> > <snip>
> >
> > I don't find this answer satisfactory. Yes, PHP has loose/weak typing,
but
> > at any one time, a value or a variable has a distinct type. In the
example
> > in the quote above, you'd have to ensure that the value you pass is of
the
> > right type.
>
> I can recognize that this answer would not be satisfactory for someone
> with a background in traditional application architecture. However, PHP
> has been developed from the beginning as a programming language for the
> web. Since the nature of web requests is to transfer all values as
> strings, PHP needs to be able to compare items of different types -- '0'
> needs to evaluate to the same thing as 0. This may not be optimal for
> many applications, but for most web applications to which PHP is
> applied, it is considered a *feature*.
Yes, and I'm not against the dynamic/loose typing of PHP. However, as
mentioned in the other reply to Rasmus Lerdorf, there may be areas in your
application where the types are well-defined (not from GET/POST), and where
this might help. Even with GET/POST requests, it's often recommended to
"sanitize"/check these before using the values, and in this process, you
might fix the types (you can't very well check a a value you don't know the
expected type for).
> > This would also open the door to overloading, although it seems from the
> > replies from Andi and Zeev in the Zend forums that neither optional
static
> > typing, nor overloading is considered at this time, and likely not in
the
> > future, either. :/
>
> PHP already supports overloading as you're accustomed to it -- the
> syntax is different, and PHP refers to the practice as "variable-lentgh
> argument lists". You use func_num_args(), func_get_args(), and
> func_get_arg() to accomplish it:
>
> function someOverloadedFun()
> {
> $numargs = func_num_args();
> $args = func_get_args();
> if (0 == $numargs) {
> return "ERROR!";
> }
> if (1 == $numargs) {
> if (is_string($args[0])) {
> return "Received string: $args[0]";
> } elseif (is_object($args[0])) {
> return "Received object!";
> }
> } elseif ((2 == $numargs)) {
> return "Received arg0 == $args[0] and arg1 == $args[1]";
> }
> // etc.
> }
>
> Yes, this is more cumbersome than providing hints
Indeed, and it means all the selection have to be done in _one_ function.
Sure, varargs can give you some kind of overloading, but as with using
assert and is_* above, to check for incoming types, you essentially have to
"manually" provide the overloading (by checking argument number and types,
and dispatching appropriately), and then the alternative of using
differently named functions really look more appealing...
Besides, this makes the "switch function" a dependency hog: Every
"overloaded" function you add means you have to change it. If it's in a
third-party library, this may not be useful option.
> > There's a rather lively discussion about adding optional static typing
in
> > Python (http://www.artima.com/weblogs/viewpost.jsp?thread=85551), and
unless
> > it has already been, maybe it's time for us to consider it for PHP, as
well.
> > The current static type checking in PHP5 is something rather half-baked,
> > only covering user-defined types.
>
> I can definitely see a use for this -- but, again, PHP has been designed
> with loose typing as a *feature*. While type hinting may be a nice
> additional feature, I have my doubts as to the necessity or overhead it
> would incur.
I certainly know that a number of bugs I've encountered could have been
found with type hints for built-in types, so I think it would be useful. The
question, of course, is whether most PHP developers don't think so. Also, we
don't have any experience with it in PHP.
Thanks for your replies.
Regards,
Terje
--- End Message ---
--- Begin Message ---
Terje Sletteb� wrote:
...
I certainly know that a number of bugs I've encountered could have been
found with type hints for built-in types, so I think it would be useful. The
question, of course, is whether most PHP developers don't think so. Also, we
don't have any experience with it in PHP.
Personally I like PHP(5) the way it is now - rather than keep adding new
functionality I would rather welcome bew/better documentation (not a dig
at the dev or the docteam - I know that there are difficult issues AND
that writing docs is a, hard and b, often is thankless task!) on SPL etc
and I do wish they had left the 'bug' in that allowed syntax like:
function (MyClass $var = null)
{
...
}
but they didn't so I changed my code - basically I don't always agree
with what the dev decide to do with the tool I use most to earn money BUT:
1. these guys are all better 'hackers' than me.
2. they hand out their work from free.
3. life is a box of choloclates... and God doesn't give a **** as to
whether I like the cherry fillings or not :-)
rgds,
Jochem.
Thanks for your replies.
Regards,
Terje
--- End Message ---
--- Begin Message ---
Terje Sletteb� wrote:
From: "Matthew Weier O'Phinney" <[EMAIL PROTECTED]>
Ah, I didn't know about that one. I didn't find it here:
http://www.php.net/mailing-lists.php How can I subscribe to it?
its alternatively call 'php internals', I have read a lot of your
questions/arguments regarding access/visibility/typehints - some of them
seem more a case of you needing to adjust to PHP's way of thinking that
that PHP necessarily does it wrong (its just very different to C/Java
:-), then again other points you make are valid - either way I'm not the
one to judge --- I just thought I'd mention that such things have been
discussed/argued over on the php internals mailing list in some depth
over the last year, i.e. you may get very short answers :-)
Regards,
Terje
P.S. Why does replies to list posting go to the sender, rather than the
list, by default? Shouldn't reply-to be set to the list, as usual? I had to
manually edit the address, to make the reply go to the list.
don't even start about these mailing list setups! - be glad they work at
all :-) - btw, it seems, that on php mailing lists reply-all is the norm
and that bottom-post are generally preferred to top-posts.
PS - I enjoyed your posts!
--- End Message ---
--- Begin Message ---
>From: "Jochem Maas" <[EMAIL PROTECTED]>
> Terje Sletteb� wrote:
> >>From: "Matthew Weier O'Phinney" <[EMAIL PROTECTED]>
> >
> > Ah, I didn't know about that one. I didn't find it here:
> > http://www.php.net/mailing-lists.php How can I subscribe to it?
>
> its alternatively call 'php internals'
Ah. I thought that was something else.
>, I have read a lot of your
> questions/arguments regarding access/visibility/typehints - some of them
> seem more a case of you needing to adjust to PHP's way of thinking that
> that PHP necessarily does it wrong (its just very different to C/Java
> :-),
That may well be. :) As mentioned, I've worked with PHP a couple of years,
but have been doing C++/Java much longer (and C before that). I have started
to adjust to the dynamic nature of PHP, and as mentioned in another post,
about variable variable functions and variables, there are some useful
things that this enables, as well.
Nonetheless, the discussion of explicit/implicit typing is a valid one, and
my posts were not at least meant to see what other people think, and if
there are other approaches that kind of compensate for the risk of bugs with
implicit/dynamic typing. Guido van Rossum (Python's creator) and some others
have argued that unit tests may make up for it. Well, unit tests are nice,
but with type checking by the compiler/runtime, you may concentrate on the
non-trivial tests instead, rather than testing something the
compiler/runtime is perfectly able to do by itself.
> then again other points you make are valid - either way I'm not the
> one to judge --- I just thought I'd mention that such things have been
> discussed/argued over on the php internals mailing list in some depth
> over the last year, i.e. you may get very short answers :-)
Well, but this is great news. :) I.e. then I have a place to look. As I said
at the start, I hadn't found discussion about this, but then, I haven't
really known which archive(s) to search, either.
Of course, people won't have to go into a discussion that has happened
before; just point to a previous one, as you did. :)
> > P.S. Why does replies to list posting go to the sender, rather than the
> > list, by default? Shouldn't reply-to be set to the list, as usual? I had
to
> > manually edit the address, to make the reply go to the list.
>
> don't even start about these mailing list setups!
LOL. :) Apparently a recurring theme. :)
> - be glad they work at
> all :-) - btw, it seems, that on php mailing lists reply-all is the norm
I use reply-all, but that also includes the sender as recipient, which I
usually edit out: No need to give them two copies of a posting.
> and that bottom-post are generally preferred to top-posts.
Aren't they everywhere. ;)
> PS - I enjoyed your posts!
Thanks. :) I haven't received any flames, yet, at least. :) I didn't really
know how they would be received, given that I don't know the community.
(I've usually been hanging around the ACCU lists, as well as Boost, and
comp.lang.c++.moderated, comp.std.c++, so I mostly know the C++ community.)
Regards,
Terje
--- End Message ---
--- Begin Message ---
I recently saw a super mode that does just what you want.
Try this link http://www.emacswiki.org/cgi-bin/wiki/HtmlModeDeluxe
dayton
>>>>> "Song" == Song Ken Vern-E11804 <[EMAIL PROTECTED]> writes:
Song> Hi, I would like the behaviour of turning on the cc-mode
Song> indentation in the <?php ?> tags but turning off when escaping and
Song> doing html.
Song> I have been looking at the cc-engine.el source and can't seem to
Song> find the place where I should change.
Song> Is this behaviour possible?
Song> thanx
--- End Message ---
--- Begin Message ---
-----Original Message-----
From: Tony Di Croce [mailto:[EMAIL PROTECTED]
Sent: 22 January 2005 23:21
To: [email protected]
Subject: [PHP] Is this even possible?
Is it even possible to connect to a postgres server (thats running on
linux) from a windows CLI php script?
I'm seeing a pg_connect() error... FATAL: no pg_hba.conf entry for
host 192.168.1.100
Any ideas?
You will need to install the client libraries, as you would for any database
- you will need to go to the Postgres web-site for details of how to do
that.
HTH,
Mikey
--- End Message ---
--- Begin Message ---
Good morning. In Windows XP, MYSQL, PHP and using the following code
snippet:
<?
$conn = mysql_connect('localhost', 'odbc', '') or die ("Can't Connect To
Database");
$db = mysql_select_db("wwpbt", "$conn") or die ("Can't Select Database");
$echo ("Congratulations - you connected to MySQL");
?>
I initially was successful. However, about 5 hours later, as I was exploring
how to SELECT and UPDATE to my db in PHP, I was not able to see any values
returned. I ran the snippet above and the only msg I can get is 'Can't
Select Database'. However when I drop the $db line, I get no msg at all. Any
Ideas would be appreciated with a caveat.............
I am building a commercial site for myself. The concept documents can be
found at POTBOWLING.COM. I cannot pay anyone for assisting me unless we have
a prior arrangement and until this thing gets off the ground bringing in
real income. Please do not send any response with the intent of making
claims against the project later unless we have an understanding.
I have already run this thing back in the '80's on a DOS based BATCH process
system, and after three failed attempts and all my money to get others to
write the code in the Web World, I am going to do it my self. At least the
proof of concept which will prove the functionality, without the bells and
whistles, that this can work, at which point I hope to acquire funding to
build the security and beef up the code, look and feel of the website. I do
have interested parties waiting to see what I can develop who are willing to
move this along.
So, with that in mind and an understanding that if you can help now, and
this thing goes, I will need a solid staff to help develop and then maintain
this project. Once this one is up and running I have also done another DOS
based project in the Golfing world. I welcome your assistance. Please reply
directly to
[EMAIL PROTECTED]
Jim Yeatrakas
Charleston SC.
--- End Message ---
--- Begin Message ---
Hello All,
I've been trying for days now to make this work.
I'm trying to search my array for a value and return the key.
I get the visitor's IP and try this -- this is the latest,
I've tried a few functions to echo the name associated with the viz_ip.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
"204.126.202.56"=>"Mark",
"63.230.76.166"=>"Bob",
"63.220.76.165"=>"John",
);
function _array_search ($viz_ip, $byte_ip) {
foreach($byte_ip as $key => $val) {
if ($viz_ip === $key) {
return($val);
}
}
return(False);
}
I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong.
I've read the examples at php.net but I just can't get it. Some help
or even a hint ?
best regards,
malcolm
--
Ommmm
--- End Message ---
--- Begin Message ---
Malcolm wrote:
Hello All,
I've been trying for days now to make this work.
I'm trying to search my array for a value and return the key.
I get the visitor's IP and try this -- this is the latest,
I've tried a few functions to echo the name associated with the viz_ip.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
"204.126.202.56"=>"Mark",
"63.230.76.166"=>"Bob",
"63.220.76.165"=>"John",
);
function _array_search ($viz_ip, $byte_ip) {
foreach($byte_ip as $key => $val) {
if ($viz_ip === $key) {
return($val);
}
}
return(False);
}
try:
function getValueInArr($val, $arr)
{
$val = (string)$val;
return is_array($arr) && isset($arr[$val]) ? $arr[$val]: false;
}
but maybe the $viz_ip really _isn't_ set in the array you have?
I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong.
I've read the examples at php.net but I just can't get it. Some help
or even a hint ?
best regards,
malcolm
--- End Message ---
--- Begin Message ---
> I've been trying for days now to make this work.
This worked for me (with my IP address for 'John'):
<?php
$viz_ip= $_SERVER['REMOTE_ADDR'];
echo ("Your IP is $viz_ip");
$byte_ip= array(
"204.126.202.56"=>"Mark",
"63.230.76.166"=>"Bob",
"84.196.101.86"=>"John",
);
function _array_search ($viz_ip, $byte_ip) {
foreach($byte_ip as $key => $val) {
if ($viz_ip === $key) {
return($val);
}
}
return(False);
}
?>
<p>Hi <?php echo (_array_search($viz_ip, $byte_ip)); ?></p>
J
--- End Message ---
--- Begin Message ---
Thank you Sirs,
I was echoing the viz-ip so I know it was getting set but
I couldn't get it.
both work .. I got the clue from John, the last echo line did the
trick.
On Sun, 23 Jan 2005 17:26:58 +0100, Jochem Maas <[EMAIL PROTECTED]>
wrote:
Malcolm wrote:
Hello All,
I've been trying for days now to make this work.
--- End Message ---
--- Begin Message ---
probably missing something but php have a function called array_search.
Ben
On Sun, 23 Jan 2005 11:33:16 -0500 (EST), [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> > I've been trying for days now to make this work.
>
> This worked for me (with my IP address for 'John'):
>
> <?php
> $viz_ip= $_SERVER['REMOTE_ADDR'];
> echo ("Your IP is $viz_ip");
>
> $byte_ip= array(
>
> "204.126.202.56"=>"Mark",
>
> "63.230.76.166"=>"Bob",
>
> "84.196.101.86"=>"John",
> );
>
> function _array_search ($viz_ip, $byte_ip) {
>
> foreach($byte_ip as $key => $val) {
>
> if ($viz_ip === $key) {
> return($val);
> }
>
> }
>
> return(False);
> }
>
>
> ?>
>
> <p>Hi <?php echo (_array_search($viz_ip, $byte_ip)); ?></p>
>
> J
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Ben Edwards - Poole, UK, England
WARNING:This email contained partisan views - dont ever accuse me of
using the veneer of objectivity
If you have a problem emailing me use
http://www.gurtlush.org.uk/profiles.php?uid=4
(email address this email is sent from may be defunct)
--- End Message ---
--- Begin Message ---
Malcolm wrote:
Hello All,
I've been trying for days now to make this work.
I'm trying to search my array for a value and return the key.
I get the visitor's IP and try this -- this is the latest,
I've tried a few functions to echo the name associated with the viz_ip.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
"204.126.202.56"=>"Mark",
"63.230.76.166"=>"Bob",
"63.220.76.165"=>"John",
);
function _array_search ($viz_ip, $byte_ip) {
foreach($byte_ip as $key => $val) {
if ($viz_ip === $key) {
return($val);
}
}
return(False);
}
I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong.
I've read the examples at php.net but I just can't get it. Some help
or even a hint ?
best regards,
malcolm
I might be the only one to notice here, but you don't want to find the
KEY, you want to find the VALUE. Otherwise, you'll need to assemble your
array differently.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
"204.126.202.56"=>"Mark",
"63.230.76.166"=>"Bob",
"63.220.76.165"=>"John"
);
That means:
$byte_ip[$viz_ip] = some_name;
That's because you have ips set as your *keys*, and not your values. To
do what you wanted, simply either:
a) reverse the array, making keys values and values keys:
$byte_ip= array(
"Mark"=>"204.126.202.56",
"Bob"=>"63.230.76.166",
"John"=>"63.220.76.165"
);
or:
b) change the function to match on key (for which you don't *need* a
function).
- Tul
--- End Message ---
--- Begin Message ---
Ah so -- array_search only works on values ?
That probably accounts for my first day or so, thanks.
I've got it now.
On Sun, 23 Jan 2005 19:22:32 +0100, M. Sokolewicz <[EMAIL PROTECTED]> wrote:
Malcolm wrote:
Hello All,
I've been trying for days now to make this work.
I'm trying to search my array for a value and return the key.
I get the visitor's IP and try this -- this is the latest,
I've tried a few functions to echo the name associated with the viz_ip.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
"204.126.202.56"=>"Mark",
"63.230.76.166"=>"Bob",
"63.220.76.165"=>"John",
);
function _array_search ($viz_ip, $byte_ip) {
foreach($byte_ip as $key => $val) {
if ($viz_ip === $key) {
return($val);
}
}
return(False);
}
I'm no wiz but this shouldn't be this hard, maybe I'm thinking wrong.
I've read the examples at php.net but I just can't get it. Some help
or even a hint ?
best regards,
malcolm
I might be the only one to notice here, but you don't want to find the
KEY, you want to find the VALUE. Otherwise, you'll need to assemble your
array differently.
$viz_ip= $_SERVER['REMOTE_ADDR'];
$byte_ip= array(
"204.126.202.56"=>"Mark",
"63.230.76.166"=>"Bob",
"63.220.76.165"=>"John"
);
That means:
$byte_ip[$viz_ip] = some_name;
That's because you have ips set as your *keys*, and not your values. To
do what you wanted, simply either:
a) reverse the array, making keys values and values keys:
$byte_ip= array(
"Mark"=>"204.126.202.56",
"Bob"=>"63.230.76.166",
"John"=>"63.220.76.165"
);
or:
b) change the function to match on key (for which you don't *need* a
function).
- Tul
--
Ommmm
--- End Message ---
--- Begin Message ---
I had a php routine on a shared server running as a CGI script that
encrypted and sent email text.
It was running fine under PHP version 4.3.6. Then the ISP upgraded to
4.3.10 on December 16, 2004 and several of the features in the gpg
encryption script running in cgi-bin stopped working.
phpinfo() in a script run from cgi-bin reports Server
API = Apache. Isn't it supposed to be CGI??
Initially, fopen(), mail(), and the passthru( ) of the gpg command would
not work.
The ISP did something, and got it back so fopen() and mail() works, but
files are still being created as "nobody nobody". The gpg command that
works from the shell, returns result=2 when run through the script.
I've tried shell_exec() also.
Isn't running the script in cgi-bin SUPPOSED TO run as myusername rather
than as nobody?
What mistakes m I making? Is this a php upgrade/configuration problem that
the ISP needs to look at, or it is a general security issue which used to
work but now is not going to be allowed... and the ISP doesn't want to
tell me?
Any thoughts or suggestions, inside or outside the box on how I can get
back to the same functionality as I had before December 16, 2004?
Thank you in advance for any help you can offer.
Best regards,
Ralph Frost
Imagine consciousness as a single internal analog language
made of ordered water, fabricated on-the-fly during respiration.
--- End Message ---
--- Begin Message ---
Dear Jason,
Thanks!
Such a stupid misstake (however in the earlier version of php I did not
received any notice). But I am not a programmer ;-)
Regards,
Tamas
>> 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
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
--
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 ---
Hi,
I'm trying to output a text file from a pdf file using an external function,
pdftotext, using either PHP's 'passthru' or 'exec' functions.
The following code sort of works (at least I see localhost busy doing
something for about three seconds, but the expected output of 'content.txt'
is empty. I used an idea found on the mailing list: I actually got some
activity with 'sudo desired_function arg1 arg2'.
File permissions are set wide open (apache:apache 777), safe_mode=off.
What am I doing wrong? (Btw, the pdftotext function works fine on
commandline).
<?php
$currentPdf = "2005-01-v2.pdf";
//print "$currentPdf";
if (file_exists($currentPdf)) {
passthru("sudo /usr/bin/pdftotext /var/www/html/2005-o1-v2.pdf.txt
/var/www/html//current.txt");
}
/* Also tried the following using 'passthru' then 'exec':
$pdf = file_get_contents($currentPdf);
//print "<br><br>$Pdf";
passthru("sudo pdftotext /var/www/html/2005-o1-v2.pdf.txt
/var/www/html/current.txt");
*/
$current = "current.txt";
print "<br><br>Current Text: $current";
$string_text = file_get_contents("current.txt");
$new_text = nl2br("$string_text");
?>
Any help, pointers, admonitions gratefully accepted,
Tia,
Andre
--- End Message ---
--- Begin Message ---
Have you tried using the backtick (``) operator? I don't know if it makes
any difference, but it might be worth a try...
HTH,
Mikey
-----Original Message-----
From: Andre Dubuc [mailto:[EMAIL PROTECTED]
Sent: 23 January 2005 21:08
To: [email protected]
Subject: [PHP] Attempting to use 'passthru' or 'exec' function
Hi,
I'm trying to output a text file from a pdf file using an external function,
pdftotext, using either PHP's 'passthru' or 'exec' functions.
The following code sort of works (at least I see localhost busy doing
something for about three seconds, but the expected output of 'content.txt'
is empty. I used an idea found on the mailing list: I actually got some
activity with 'sudo desired_function arg1 arg2'.
File permissions are set wide open (apache:apache 777), safe_mode=off.
What am I doing wrong? (Btw, the pdftotext function works fine on
commandline).
<?php
$currentPdf = "2005-01-v2.pdf";
//print "$currentPdf";
if (file_exists($currentPdf)) {
passthru("sudo /usr/bin/pdftotext /var/www/html/2005-o1-v2.pdf.txt
/var/www/html//current.txt");
}
/* Also tried the following using 'passthru' then 'exec':
$pdf = file_get_contents($currentPdf);
//print "<br><br>$Pdf";
passthru("sudo pdftotext /var/www/html/2005-o1-v2.pdf.txt
/var/www/html/current.txt");
*/
$current = "current.txt";
print "<br><br>Current Text: $current";
$string_text = file_get_contents("current.txt");
$new_text = nl2br("$string_text");
?>
Any help, pointers, admonitions gratefully accepted,
Tia,
Andre
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On Monday 24 January 2005 05:08, Andre Dubuc wrote:
> I'm trying to output a text file from a pdf file using an external
> function, pdftotext, using either PHP's 'passthru' or 'exec' functions.
>
> The following code sort of works (at least I see localhost busy doing
> something for about three seconds, but the expected output of
> 'content.txt' is empty. I used an idea found on the mailing list: I
> actually got some activity with 'sudo desired_function arg1 arg2'.
>
> File permissions are set wide open (apache:apache 777), safe_mode=off.
>
> What am I doing wrong? (Btw, the pdftotext function works fine on
> commandline).
1) What does your php error log say?
2) Is there any reason you're using sudo? Do you know how it works and have
you configured sudo correctly?
3) Commands like passthru() and exec() allow you to check the return value of
the system command being executed -- use it.
--
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 ---
hi, i have a script that parses data from xml document
my problem is sometimes i get error when getting file content from xml
file fails
so how can u make the script ignore that part when it fails to pull
the data from the xml file.
here is the script :
$xp = xml_parser_create();
xml_set_character_data_handler($xp,'h_char');
xml_set_element_handler($xp,'h_estart','h_eend');
$listing = 0;
$found_listings = array();
$tag_name = '';
xml_parse($xp,file_get_contents("http://someXMLdocument.xml"));
function h_char($xp,$cdata) {
global $listing, $tag_name;
if (is_array($listing) and $tag_name) {
$listing[$tag_name] .=
str_replace(''',"'",str_replace('&','&',str_replace('\\$','$',$cdata)));
}
return true;
}
function h_estart($xp,$name,$attr) {
global $listing, $tag_name;
if ($name == 'SITE') {
$listing = array();
}
else {
$tag_name = strtolower($name);
}
return true;
}
function h_eend($xp,$name) {
global $listing, $tag_name, $found_listings;
if ($name == 'SITE') {
$found_listings[] = $listing;
$listing = null;
}
$tag_name = '';
return true;
}
echo "hi, i am xml data"
xml_parser_free($xp);
can anyone help me with that please?
--
Ahmed Abdel-Aliem
Web Developer
www.ApexScript.com
0101108551
--- End Message ---
--- Begin Message ---
Burhan Khalid wrote:
Tim Burgan wrote:
Hello,
I've developed my site, and tested on a web host (Apache, PHP 4.3.9).
Now I've uploaded to a different host (IIS, PHP 4.3.1) where I want to
keep it, and I get session error messages like:
Warning: session_start() [function.session-start
<http://www.php.net/function.session-start>]:
open(/tmp\sess_30f6794de4b0d80b91035c6c01aae52d, O_RDWR) failed: No
such file or directory (2) in
E:\W3Sites\ywamsa\www\timburgan\index.php on line 9
Warning: session_start() [function.session-start
<http://www.php.net/function.session-start>]: Cannot send session
cookie - headers already sent by (output started at
E:\W3Sites\ywamsa\www\timburgan\index.php:9) in
E:\W3Sites\ywamsa\www\timburgan\index.php on line 9
The problem is that the php installation on this server is not
configured correctly. It still holds the default session location
(/tmp) which doesn't exist on Windows PCs.
You need to ask the server administrator to verify the PHP installation
and point the session location directory to a valid location on the server.
You also have the option of creating your own session location directory
by inserting the following at the beginning of each script.
session_save_path('...public/tmp');
I happen to do this because my hosting company uses load balancing which
means I can never know what server is processing my PHP script. I place
my session location in a tmp folder in my public directory. Otherwise I
would lose my session variables periodically.
--
Jerry Kita
http://www.salkehatchiehuntersville.com
email: [EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
Thankyou. That solved the issue.
I didn't know that function existed.
Tim
--- End Message ---
--- Begin Message ---
I've installed Apache 2 and PHP 5 on Windows XP, and I'm having some
issues with sessions. Everything else I've tried to do in PHP works
fine, but for some reason every time I try to use session_start() i
get the following errors:
Warning: session_start() [function.session-start]:
open(C:\PHP\sessiondata\sess_29eb1a211c118cc8083168f24e32ee75, O_RDWR)
failed: No such file or directory (2) in C:\Program Files\Apache
Group\Apache2\htdocs\Games\main.php on line 3
Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at C:\Program
Files\Apache Group\Apache2\htdocs\Games\main.php:3) in C:\Program
Files\Apache Group\Apache2\htdocs\Games\main.php on line 3
Warning: session_start() [function.session-start]: Cannot send session
cache limiter - headers already sent (output started at C:\Program
Files\Apache Group\Apache2\htdocs\Games\main.php:3) in C:\Program
Files\Apache Group\Apache2\htdocs\Games\main.php on line 3
Any suggestions?
Sam
--- End Message ---
--- Begin Message ---
We are evaulating the idea of writing a PHP application server. Its aimed
to be a stateful environment for writing PHP applications and we believe
it will be quite advantegous to the entire community.
Any ideas if there are a similar solutions that already exists out there,
and what is the general feel of a solution like this.
Thanks for your time and feedback.
Devraj
---
Devraj Mukherjee ([EMAIL PROTECTED])
Eternity Technologies Pty. Ltd. ACN 107 600 975
P O Box 5949 Wagga Wagga NSW 2650 Australia
Voice: +61-2-69717131 / Fax: +61-2-69251039
http://www.eternitytechnologies.com/
--- End Message ---