[PHP] Re: XML Parsing simpleXML Arrays Question

2007-01-15 Thread Myron Turner

Richard Luckhurst wrote:

Hi List

I have taken the advice of a number of people on the list and am back trying to
write my XML parser using SimpleXML. I am having a problem and I believe the
problem is my lack of understanding of arrays and simpleXML in spite of much
google searching and manual reading. I would appreciate some help.

The piece of XML I am parsing is as follows. I am working with a small section
to see if I can get my head around it.





  
AA
PR
  


If I use the following

$file = "test.xml";


  $data = simplexml_load_file($file);

  foreach ($data->vcrSummary as $vcrSummary)

  {
var_dump($vcrSummary); 
   }


Then I get

object(SimpleXMLElement)#5 (1) {
  ["vcr"]=>
  array(2) {
[0]=>
string(2) "AA"
[1]=>
string(2) "PR"
  }
}

Which is pretty much what I would expect as there are 2 vcr tags.

If I then use

$file = "test.xml";


$data = simplexml_load_file($file);


foreach($data as $vcrSummary)
{
$z = $vcrSummary->vcr;
print "$z \n";


}


I get 3 blank lines and then AA which is the first of the two vcr values. The
examples I am looking at suggest I should have gotten both of the vcr values.

Many of the examples I am looking at say to use echo instead of print, eg

echo $vcrSummary->vcr;

and that just gives me AA and not both values that I would expect.

Can anyone point me in the right direction here.

Regards,
Richard Luckhurst  
Product Development

Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]





  
currency="USD">AA
currency="USD">PR

  

XML;

$xml = simplexml_load_string($string);

echo "VCR - 0\n";
echo $xml->vcrSummary->vcr[0] ."\n";
echo "Min Price: " . $xml->vcrSummary->vcr[0]['minPrice'] ."\n";

echo "\nVCR - 1\n";
echo $xml->vcrSummary->vcr[1] ."\n";
echo "Min Price: " . $xml->vcrSummary->vcr[1]['minPrice'] ."\n";

/* Result:
Result:
VCR - 0
AA
Min Price: 1667

VCR - 1
PR
Min Price: 1374

*/
?>

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Parsing AJAX post data -- The Way

2007-01-25 Thread Myron Turner

[EMAIL PROTECTED] / 2007-01-24 23:41:19 -0700:
Just wondering what smart people do for parsing data sent by the  
Javascript XMLHTTP object--e.g., http.send("post",url,true)...


In a normal form submit, the $_POST global nicely allocates form  
elements as array elements automatically. But with the AJAX way, the  
data get stuffed inside $HTTP_RAW_POST_DATA as a string, thereby  
making extraction more tedious.



Try setting this header before sending your Ajax request:

http_request.setRequestHeader("Content-type", 
"application/x-www-form-urlencoded");


Then $_POST should have an array, as expected.  But $HTTP_RAW_POST_DATA 
will not be available.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: two php.ini on the same server

2007-01-26 Thread Myron Turner

zerof wrote:

phpdevster escreveu:

Hi

i am trying to run two Apache server on the same machine and that is 
work

fine

but the problem is how to create separate php.ini for each Apache 
server .

is that possible ??


Two usual possibilities:

1) To install two Apache Services ( Windows environment )

   Apache 1.3.xx running php 4
   Apache 2 running php 5

   http://www.educar.pro.br/

2) To use only one Apache2 Service

   Setting two virtual hosts, one for php4 and other for php5

   http://foundationphp.com/tutorials/apache22_vhosts.php
I've done this (1) on linux and it works fine, php 4 on 1.3xx and 5 php 
5 on apache 2.   I believe the reason this works is that you have two 
php executables, each with unique configurations.  So, if you, say, 
wanted to have php 5 running two apache servers, it would probably work 
if you recompile php 5 and install it into a new directory.  I have no 
experience with windows.  But here are some notes for installing on 
linux/unix machines:


If your system already came with a pre-installed php 5 executable, then 
when you download and compile the new php 5, it will automatically 
install in /usr/local.  But if you had previously compiled php 5 and it 
is already in /usr/local, you might want to install in a new directory, 
which you can do by feeding configure a new prefix:

  ./configure --prefix=/usr/local/new_install_directory
You might also want to feed configure a path for the php.ini file:
  ./configure --prefix=/usr/local/new_install_directory 
--with-config-file-path=PATH

But if you don't, php.ini will automatically be installed in PREFIX/lib:
  /usr/local/new_install_directory/lib

You will have to read the INSTALL file that comes with the 
distribtution, becaue you also have to set a few other basic values for 
configure to work with.



--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] php & javascript interaction

2007-01-26 Thread Myron Turner

William Stokes wrote:

Hello,

I need some advice on how to learn Javascript and PHP interaction. Any good 
tutorials on the web would be most welcome. I particulary need to learn how 
to pass JS user input/choices to PHP.


My current problem is how to ask user confirmation over his actions on a web 
form after POST. "Are you sure" type questions and how to pass the user 
choice back to program make choices with PHP.


Thanks
-Will

  
For the second question try google with something like "javascript form 
submit".


For the first question, see:
http://ca.php.net/manual/en/language.variables.predefined.php
Form data is captured in PHP in a number of different predefined 
variables accessible from your scripts.  This page defines these varibables.


--

_________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] navigation

2007-01-27 Thread Myron Turner

koen wrote:

How to creat the effect of the explorers back and forward buttons in php?

  


It's a javascript issue, using the javascript history object.

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Can a class instance a property of another class

2007-01-27 Thread Myron Turner

Ken Kixmoeller -- reply to [EMAIL PROTECTED] wrote:
OK, Jochem, I adapted your example and got it working. Thank you very 
much.


I am still playing with it to better understand. One thing I don't yet 
understand is the necessity for the getFoo()/getBar() "handshake," 
especially the getbar() in the BAR class. That doesn't seem to serve 
any purpose. My adaptation us just a getDummy().


Do they just serve to pass the object by reference?


Ken

--
On Jan 26, 2007, at 5:47 PM, Jochem Maas wrote:




class Foo
{
private $var;
function __construct() { $this->var = "foo"; }
function getFoo() { return $this->var; }
}

class Bar
{
private $var;
private $foo;
function __construct() { $this->var = "bar"; $this->foo = new Foo; }
function getBar() { return $this->var; }
function speak() { echo "I am 
",$this->foo->getFoo(),$this->getBar(),"\n"; }

}




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




Assigning another class to a class variable is a standard OO technique, 
so it's not surprising that it's implemented in PHP.  I believe it's 
called "composition", though that term seems to have a wider definition.


What is it that seems odd about what you call the getFoo()/getBar() 
"handshake" ?  Actually, what do you mean by that?  I could be missing 
something, but at the moment the two classes and their calls seem pretty 
straight-forward.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: [BULK] [PHP] Use array returned by function directly?

2007-01-29 Thread Myron Turner

Roman Neuhauser wrote:

# [EMAIL PROTECTED] / 2007-01-29 15:27:21 +:
  

# crash
#assert(2 == returns_array()['c']);



  

# still crash
#assert(2 == returns_array()['c']);



s/crash/syntax error/

  

You can do this in Perl:
   my $c = (fn(@a))[2];
But in PHP, this is a syntax error:
  $c = (fn($a))[2];

Also, it's not clear what the original syntax is meant to do:
   explode($needle, $array)[3]
explode() takes a string and converts it to an array based on the 
separator expression.  This might make sense:

   explode($needle, $array[3])
where $array[3] is a string.

But explode($needle, $array), it turns out, simply returns the string 
"Array".








--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: [BULK] [PHP] Use array returned by function directly?

2007-01-29 Thread Myron Turner

Roman Neuhauser wrote:

# [EMAIL PROTECTED] / 2007-01-29 10:12:25 -0600:
  

Roman Neuhauser wrote:


# [EMAIL PROTECTED] / 2007-01-29 15:27:21 +:
  

# crash
#assert(2 == returns_array()['c']);

# still crash

#assert(2 == returns_array()['c']);


s/crash/syntax error/
  

You can do this in Perl:
   my $c = (fn(@a))[2];



Not to mention C++, Python, or quite a few other languages.

  

But in PHP, this is a syntax error:
  $c = (fn($a))[2];

 
Well, DUH! THat's what the OP was curious about: why is it an error?


  

Also, it's not clear what the original syntax is meant to do:
   explode($needle, $array)[3]
explode() takes a string and converts it to an array based on the 
separator expression.  This might make sense:

   explode($needle, $array[3])
where $array[3] is a string.

But explode($needle, $array), it turns out, simply returns the string 
"Array".



Not at all! Watch this:



  

I thought the issue was this:


$array = 'O M F G';
$needle = ' ';
$array_2 = array('O', 'M', 'F', 'G');
assert($array == explode($needle, $array_2));




--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/



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



Re: [PHP] Parsing mail file

2007-01-30 Thread Myron Turner

Jim Lucas wrote:
he wants a cut/paste answer to his problem.  He doesn't want to build 
something and learn how it all works.  He just wants it to work out of 
the box.


Why would someone want to read an RFC if he didn't have to?  Maybe we 
should all start by writing our own GUI's.  Nothing like having to learn 
how to map video memory in C and assembler, as we had to do before Windows.


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



Re: [PHP] Help with matching numbers 0-100

2007-02-03 Thread Myron Turner

Chilling Lounge Admin wrote:

Hi.

I need help with matching a variable. The variable would be e.g. 0-15
, 16-30 etc. and when the variable is equal to a certain range, it
would echo an image.

Does anyone know what function I should use? preg_match?

The code would be something like

if(preg_match("[16-30]",$variable))
{
echo "image";
}

but the above code doesn't work. How do I fix it?

Thanx



if(preg_match('/(\d+)/', $variable, $matches) {
  if($matches[1] > N && $matches[1] < N2) {
  /  do your thing
 }
}

 4 && $matches[1] < 20) {
  echo $matches[1] . "  is in range\n";
 }
 else echo $matches[1] . " out of range\n";
}
?>

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Pop up window in PHP code

2007-02-03 Thread Myron Turner

Chris Carter wrote:

I am trying to open a Java script pop up widow from within the php code. Not
able to get it done, the error I think is in the use of "" '' .. I mean
double and/or single quote. Do not know how to place those. Please advice.
The code is below:

echo "

$shopname 
$category 
$subcategory 
$level 
 javascript:poptastic( Details 
";
$i++;

The javascript code works perfect with other pages and within HTML, its just
that the PHP is not supporting the quotes and double quotes. I have even
tried &rsquo &rdquo and all.
  


Where are the problem quotation marks?  And Is this in fact the actual 
html that you are outputting? 


 javascript:poptastic( Details 

Shouldn't it be:
hello

Without the a tag, it just prints the javascript pseudo-url to the 
screen as text.




--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Peristent Listen over an HTTP connection

2007-02-04 Thread Myron Turner

chetan rane wrote:

same TCP creation,

because i i am bindiing that stream to the Server.

i am actually creating a component.

a component which resides in between a client and server

i accept HTTP requests from a client and relay the same uysing a TCP
connection to the SERVER.
and vice versa

i think this makes it clear.
I think what you want to look for is how to write a socket server.  
You'll find a lot about this via google.  A socket server lets you  
open  up a persistent port for listening with a process that runs 
continually in the background and then allows you to spawn off multiple 
sockets as they come in, like a web server or ftp or ssh.  My guess is 
that there's a fair amount of complexity here that you'll have to 
investigate.  For instance, you'll have to preempt port 80, the standard 
port on which httpd listens, forward the http request to your web server 
on a local port, retrieve the response and pass it back to the client.  
And presumably you'll have to be doing this for multiple clients.
I think someone on this list suggested using AJAX.  That would be much 
simpler.  If you had to have data persistence, for instance, you could 
store data in temporary files on the server or in temporary database 
entries, or you could simply pass data back and forth using POST.  The 
script which handles the AJAX requests would be the "component" that 
resides on the server.



_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Peristent Listen over an HTTP connection

2007-02-04 Thread Myron Turner

chetan rane wrote:

same TCP creation,

because i i am bindiing that stream to the Server.

i am actually creating a component.

a component which resides in between a client and server

i accept HTTP requests from a client and relay the same uysing a TCP
connection to the SERVER.
and vice versa

i think this makes it clear.

On 2/4/07, Stut <[EMAIL PROTECTED]> wrote:


chetan rane wrote:
> i want to write a script
> where , when ny client requests come i read the stream and then process
it
>
> here is the exact steps
>
> when the user first initiates
> i create a session and establish a TCP connection
> second: when teh user next sends a request i dont create a new TCP
> connection but use the existing TCP connection.

Ok, couple of questions...

1) Why?
2) Why?

What is making these connections from the client side?

-Stut






As a follow-up to my previous, try this:
   http://www.devshed.com/c/a/PHP/Socket-Programming-With-PHP/

It needs IE (as opposed to Firefox).

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] preg_match

2007-02-06 Thread Myron Turner

James Lockie wrote:
I am trying to use this code to display a button at the root but it 
always displays the button. :-(


   if (! (preg_match( "/$\/index.php/", $_SERVER['PHP_SELF'] ))) {
# display a button



You got the end-of-string character ($) in the wrong place:
if (! (preg_match( "/\/index.php$/", $_SERVER['PHP_SELF'] ))) {


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] JS prompt -> php

2007-02-07 Thread Myron Turner

Ryan A wrote:

Hey all!

Quick question (and hopefully a simple one)

I have a link on a page, when the client clicks that link it should show them a 
JS prompt and ask for their name (so far I have done this)

When they write their name, I want that data to be sent to my php script via 
AJAX (yes?) so the page does not reload or anything (actually, how can i 
reload the page to reflect the change?)

I have googled but I see whole ajax classes and what not, I dont know if I am 
using the correct keywords or what...  you would happen to have a working piece 
of code that you could share with me.. would you?

Thanks!
Ryan


--
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)
 
-

Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
  


Google Ajax How-to or Ajax How-to POST

The 3rd or 4th item for plain how-to is:
  http://swik.net/Ajax/How+to+use+XMLHttpRequest

This first item for how-to POST:
http://www.captain.at/howto-ajax-form-post-request.php



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] PHP4 to PHP5 issue

2007-02-07 Thread Myron Turner

Christopher Weldon wrote:
You actually don't even have to run a second instance of Apache. From 
what I've heard of other hosting companies doing, you can use the same 
Apache installation and run PHP4 and PHP5 concurrently.


However, the only thing you'd have to do is one of the following:

1) For PHP4 apps and scripts, leave the .php extension and rename all 
PHP5 apps and scripts with a .php5 extension. Where you have the string:


DirectoryIndex index.php index.html

add: index.php5 to it. And where you have the string:

AddType application/x-httpd-php .php

Change it to:

AddType application/x-httpd-php4 .php

Also, add another line:

AddType application/x-httpd-php5 .php5

Make sure you include both the php4 and php5 modules, restart apache 
and voila! PHP4 and PHP5 on the same server using 1 installation of 
Apache.


2) Do the same as above, but use .php4 extensions instead of .php5.

3) Additionally, after doing 5 minutes of Googling, I found that you 
can have .htaccess files to control which applications use PHP4 and 
which use PHP5 with the following directive:


AddHandler application/x-httpd-php5 .php

This would circumvent having to rename the extensions of your PHP 
files, as you could then do directory specific PHP4/5 app running. You 
still have to make certain Apache has both the PHP4 and PHP5 modules 
loaded, obviously.

--
This has come up a few times recently, and I added my own two cents, 
which required two separate Apaches installs on the same server, which 
I'd done for myself.  But this solution is really cool!


--

_________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] PHP4 to PHP5 issue

2007-02-07 Thread Myron Turner

Jochem Maas wrote:

Myron Turner wrote:
  

Christopher Weldon wrote:


You actually don't even have to run a second instance of Apache. From
what I've heard of other hosting companies doing, you can use the same
Apache installation and run PHP4 and PHP5 concurrently.
  


if you use CGI for one of them then yes - but not if you [want to] use the 
apache
module for both of them, this is due to symbol clashes between php4 and php5 
modules
when they are loaded simultaneously.

please correct me if I have the wrong end of the stick.

  
Thanks for the heads up.  I'm sure I would have tried it out, probably 
sooner than later.  Maybe someone has some further advice on this.


--

_________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Text Editor for Windows?

2007-02-08 Thread Myron Turner

Stephen wrote:

I am finding that notepad is lacking when correcting syntax errors in my php 
code. No line numbers.

What can people recommend for use under Windows?

Thanks
Stephen

  
 I've recommended this before, Programmer's File Editor.  I never leave 
home without it and have been using it for years.  It's free, though no 
longer being developed, and while it doesn't do text highlighting, etc. 
it does have many features needed by programmers, like line numbers, 
matching braces and parenthesis,  automatic indenting based on your own 
style,  code execution, creating macros, and it can be highly customized 
for individual use.  It will not, however, find syntax errors. 



--

_________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] base64-encoding in cookies?

2007-02-10 Thread Myron Turner

Jon Anderson wrote:

Fletcher Mattox wrote:

In terms of the behavior, I think it makes total sense. The only case 
where it would ever bite you is yours (which is rare because most 
people wouldn't mix perl and PHP in the same system).


I'm not going to get into the middle of the base64 argument, but I don't 
think that mixing perl and php is rare.  I've seen the mix occasionally 
crop up up this list, and I know from myself.  I've been using Perl for 
10 years and PHP for only 2.5.  It's inevitable that I'll choose Perl 
for certain uses and that I'll call the Perl as cgi from  pages scripted 
in PHP.  Then there are things which I've already got written in Perl 
that I also call as cgi from PHP pages.  Or operations that are not 
compiled into all installs of PHP and are standard with Perl, like 
fork(), and there's nothing you can do about it because you don't have 
control over the installation.  Each language has its strengths.  What's 
true of Perl, I think is probably true of Python as well.  There are 
lots of programmers and web sties that must mix Python and PHP. 


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Eregi error

2007-03-01 Thread Myron Turner

M.Sokolewicz wrote:

Hey all,
I have been having some trouble with the "eregi" function. I have 
the following piece of code in my application:


   function standard_input($input, $min=0, $max=50){
   if (strlen($input) <= $max and strlen($input) >= $min ) {
   $pattern = '^[a-z0-9\!\_ \.- ,/]*$';
   if(!eregi($pattern, $input)){
   return false;
   }else{
   return true;
   }
   }else{
   return false;
   }
 }

And i am running PHP version 5.2.1

I receive the following error:
*Warning*: eregi() [function.eregi 
<http://idontwanttouse.net/MeetMyMate/Bin/Debug/function.eregi>]: 
REG_ERANGE in *[File Location]* on line *287


the problem is that the hyphen is interpreted as regex range operator:
 [a-z0-9\!\_ \.- ,/]
Rewrite this as
   [a-z0-9\!\_ \. ,/-]
with the hyphen in the last position.

--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Eregi error

2007-03-01 Thread Myron Turner

Roberto Mansfield wrote:

Myron Turner wrote:
  

M.Sokolewicz wrote:


   $pattern = '^[a-z0-9\!\_ \.- ,/]*$';
   if(!eregi($pattern, $input)){
  

the problem is that the hyphen is interpreted as regex range operator:
 [a-z0-9\!\_ \.- ,/]
Rewrite this as
   [a-z0-9\!\_ \. ,/-]
with the hyphen in the last position.




Or just escape the hyphen: \-
The position won't matter.

  


Actually, I tried that, but it didn't work.  It still saw the hyphen as 
an operator.  The other thing about this is that the hyphen is followed 
by a space, so that it's asking for a range between the period and the 
space, which you can't do, since the space character has a lower ascii 
value than than the period.  The space is more obvious in a monospaced font.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] problem generating a file link

2007-03-05 Thread Myron Turner
There's nothing wrong with this. It's standard. I believe the logic of 
this is that the first two forward slashes represent the standard 
protocol indicator: http://, ftp://, file://, while the final forward 
slash represents a directory off the root directory, as a carry over 
from unix

/tmp, /bin, /usr, etc.

George Pitcher wrote: 

Jochem,

  

I have tried variations on the following:

$storelink = "PDF";

and the link keeps coming out as:

file:///G:/575991.pdf
  

is that what the browser (let me guess: IE) is interpreting
the link as or is that what is literally in the html source?



I'm using Smarty so the link doesn't appear as HTML as such. This is what
the browser (guessed wrong - I'm using Firefox) shows in the status bar.

George

  



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/




[PHP] Re: [PHP-DB] array field type

2007-03-06 Thread Myron Turner

Tony Marston wrote:
"Sancar Saran" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
 

On Sunday 04 March 2007 23:04, Sancar Saran wrote:
   

Hi,

I want to know is there any db server around there for store php arrays
natively.

Regards

Sancar
  

Thanks for responses, it seems I have to give more info about situation.

In my current project, we had tons of arrays. They are very deep and
unpredictable nested arrays.

Currently we are using serialize/unserialize and it seems it comes 
with own
cpu cost. Xdebug shows some serializing cost blips. Sure it was not 
SO BIG

deal (for now of course).

My db expertise covers a bit mysql and mysql does not have any array 
type

field (enum just so simple).



Wrong! Take a look at the SET datatype 
http://dev.mysql.com/doc/refman/4.1/en/set.html. This allows you to 
have an array of values in a single field, and the user can select any 
number of them.


  
It might be worth looking at wddx.  I can't speak about the cpu cost for 
large numbers of arrays, but it's mechanism is simple.  It saves data 
types as XML strings, which can be written using 
**wddx_serialize_vars()*  *and read 
using **wddx_deserialize()* .





--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Urgent: Way to XML-parse data with tags?

2007-03-08 Thread Myron Turner

Rob Gould wrote:


The problem I'm having is that the XML data that comes back from the 
host doesn't just have   tags.  It has n="eventname">datahere tags, and I don't know how to get the XML 
parser to read the values using that format.  (And I don't have 
control over the host)  As a first step, I just want to retrieve the 
"eventname", "venuename", and "venuecity" data from within the 
"result" tags at the bottom of the data.


I'm really hoping this is possible with PHP - - - can someone please 
steer me in the right direction and tell my what I should change in 
the below script?  The $tag value is not getting a value string, due 
to the XML-data


Here's my present script:

   
} elseif ($name == "RESULT") {

echo "found result";
$insideitem = true;
}
}

?>


You'll get these from the attributes array, which is an associative array:

   The third parameter, /attribs/, contains an associative array with
   the element's attributes (if any).The keys of this array are the
   attribute names, the values are the attribute values.Attribute names
   are case-folded
   <http://www.php.net/manual/en/ref.xml.php#xml.case-folding> on the
   same criteria as element names.Attribute values are /not/ case-folded.

   From:  
   http://www.php.net/manual/en/function.xml-set-element-handler.php



So $venuecity - $attrs['venuecity'], etc.

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





--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/




[PHP] Re: I almost get what you're saying...

2007-03-08 Thread Myron Turner

Rob Gould wrote:

Myron,

Thank you thank you!  You've pointed me in the right direction - - - - 
but I'm so new to PHP that I need just a "little more" pointing


From reading the docs, I understand that I need to pull from an 
associative array, and you are correct that "$venuecity = 
$attrs['venuecity']".  I'm just a little lost as to where I use this 
knowledge in the below code.  Do I need to create a new function-call 
to focus on pulling out associative arrays, or can I just use 
$attrs['venuecity'] somewhere below?  If I could ask you to help me 
with just one array, I'm sure I can figure out the rest.



   
} elseif ($name == "RESULT") {

echo "found result";
$insideitem = true;
}
}


You get the attributes array right here in startElement$parser, $name, 
$attrs) :


function startElement($parser, $name, $attrs) {
   global $insideitem, $tag, $eventname, $venuename, $venuecity;

/if(isset($attrs['venuecity'])) {
   $venuecity = $attrs['venuecity'];
  }
// etc.

}


_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Urgent: Way to XML-parse data with tags?

2007-03-08 Thread Myron Turner

Myron Turner wrote:

Rob Gould wrote:


The problem I'm having is that the XML data that comes back from the 
host doesn't just have   tags.  It has n="eventname">datahere tags, and I don't know how to get the XML 
parser to read the values using that format.  (And I don't have 
control over the host)  As a first step, I just want to retrieve the 
"eventname", "venuename", and "venuecity" data from within the 
"result" tags at the bottom of the data.


I'm really hoping this is possible with PHP - - - can someone please 
steer me in the right direction and tell my what I should change in 
the below script?  The $tag value is not getting a value string, due 
to the XML-data


Here's my present script:



You'll get these from the attributes array, which is an associative 
array:


   The third parameter, /attribs/, contains an associative array with
   the element's attributes (if any).The keys of this array are the
   attribute names, the values are the attribute values.Attribute names
   are case-folded
   <http://www.php.net/manual/en/ref.xml.php#xml.case-folding> on the
   same criteria as element names.Attribute values are /not/ case-folded.

   From: 
http://www.php.net/manual/en/function.xml-set-element-handler.php



So $venuecity - $attrs['venuecity'], etc.

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






I misread your original xml.  It seems that your attribute names are "n"?
   n="eventname"
Then it's n which will be the key in the attributes array:
$attrs['n'].

Perhaps it would help if  you gave use the actual xml and not just this 
schematic.  The file your refer us to can't be downloaded.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Urgent: Way to XML-parse data with tags?

2007-03-08 Thread Myron Turner

Myron Turner wrote:

Rob Gould wrote:


The problem I'm having is that the XML data that comes back from the 
host doesn't just have   tags.  It has n="eventname">datahere tags, and I don't know how to get the XML 
parser to read the values using that format.  (And I don't have 
control over the host)  As a first step, I just want to retrieve the 
"eventname", "venuename", and "venuecity" data from within the 
"result" tags at the bottom of the data.


I'm really hoping this is possible with PHP - - - can someone please 
steer me in the right direction and tell my what I should change in 
the below script?  The $tag value is not getting a value string, due 
to the XML-data


Here's my present script:



You'll get these from the attributes array, which is an associative 
array:


   The third parameter, /attribs/, contains an associative array with
   the element's attributes (if any).The keys of this array are the
   attribute names, the values are the attribute values.Attribute names
   are case-folded
   <http://www.php.net/manual/en/ref.xml.php#xml.case-folding> on the
   same criteria as element names.Attribute values are /not/ case-folded.

   From: 
http://www.php.net/manual/en/function.xml-set-element-handler.php



So $venuecity - $attrs['venuecity'], etc.

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





OK.  I was able to get hold of the file.  Here's a small part of the 
listing:


  xphoenix;Paradise Valley;Greater Phoenix
  Remembering Amy
  REMEMBERING AMY
  3288076
  670;409;1957
  AZ

What you want to do here is to process the file, as you were doing, 
checking for the attribute value you want, then capture
the element data once the attribute name is found.  Here's a way to do 
that (not tested but should work):


$eventname = "";
$venuename = "";
$venuecity = "";
$found = "";

function startElement($parser, $name, $attrs) {
  global  $eventname, $venuename, $venuecity;

 // speed up the parsing since all the values have been found
 if(!empty($eventname)  && !empty($eventname) && !empty($eventname)  {
   return;
 }

   $found = $attrs['n'];
}

function characterData($parser, $data) {
   global  $eventname, $venuename, $venuecity;

 // speed up the parsing since all the values have been found
 if(!empty($eventname)  && !empty($eventname) && !empty($eventname)  {
   return;
 }

 switch ($found) {
   case 'eventname':
  $eventname = $data;
   break;

   case 'venuename':
  $venuename = $data;
   break;
  
   case 'venuecity':

  $venuecity = $data;
 break;
  }


}

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] FW: looking for two remote functions

2007-03-10 Thread Myron Turner

Tijnema ! wrote:

On 3/10/07, Németh Zoltán <[EMAIL PROTECTED]> wrote:


2007. 03. 10, szombat keltezéssel 12.42-kor Riyadh S. Alshaeiq ezt írta:
> Actually if right click on any file or folder on a machine you will 
see

that
> there are two values (Size on disk & Size). Files and folders are 
stored

on
> the disk in what is called clusters (a group of disk sectors). Size on
disk
> refers to the amount of cluster allocation a file is taking up, 
compared

to
> file size which is an actual byte count.
>
> As I mentioned before what I want is a function for getting the result
for
> the Size no for Size on Disk

okay then what about this?

function real_filesize_linux($file) {
  @exec("filesize $file",$out,$ret);
  if ( $ret <> '0' ) return FALSE;
  else return($out[0]);
}

if you want it on a remote machine, you should use something like
ssh2_exec() instead of exec()

hope that helps
Zoltán Németh



He was interested on using it over HTTP, not over SSH...
I don't know if there are faster ways, but you could open a socket to the
host on port 80, get the file, and only read the header where it says
content-length: 400 for example, then you know the file is 400bytes 
when you

download it.
something like:
$socket = fsockopen($host,$port);
$size = 0;
while($size == 0)
{
$line = fgets($socket);
if(strlen($line) >= 17)
{
if(substr(strtolower($line),0,14) == "content-length")
{
$size = substr($line,16)
}
}

Now your remote file size is in $size.
It is not too fast, but everything in PHP is fast and so is this.

Tijnema



>
> Riyadh
>
> -Original Message-
> From: Németh Zolt?n [mailto:[EMAIL PROTECTED]
> Sent: 10/Mar/2007 12:27 PM
> To: Riyadh S. Alshaeiq
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] FW: looking for two remote functions
>
> I'm afraid I don't understand what you want. The size of a file is its
> size in bytes, that is its size on the disk. So what else?
>
> greets
> Zolt?n Németh
>
> 2007. 03. 10, szombat keltezéssel 06.07-kor Riyadh S. Alshaeiq ezt 
?rta:
> > Thank you Mickey, but I have already looked in there and the 
function

> posted
> > in the notes is working just fine for getting the size on disk 
which I

am
> > not interested in..
> >
> > Riyadh
> >
> > -Original Message-
> > From: Mikey [mailto:[EMAIL PROTECTED]
> > Sent: 9/Mar/2007 2:57 PM
> > To: php-general@lists.php.net
> > Subject: Re: looking for two remote functions
> >
> > Riyadh S. Alshaeiq wrote:
> > > Hello everybody,
> > >
> > >  I am looking for an HTTP function for getting remote filesizes.
Keeping
> > in
> > > mind that I am NOT interested in getting the "size on disk" 
figure,

I
> need
> > > the actual size of the files when downloaded to a local machine.
Please
> > let
> > > me know if there are any..
> > >
> > > Another thing, I also need a remote function that gets the created
date
> > and
> > > last modified separately, if possible..
> > >
> > > Best regards
> > >
> > >
> > >
> > >
> >
> > Try looking here:
> >
> > http://uk.php.net/manual/en/function.filesize.php
> >
> > If the function itself isn't of use to you, look further down in the
> > notes and I am sure you will find something useful.
> >
> > Mikey
> >
>

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




This question has come up before, and out of curiosity I did some 
checking.  If you use firefox liveheaders, it turns out that the file 
size on the linux file system is exactly the size shown in the 
content-length header. This is also the same size as returned by php's 
filesize() and by the php stat() in its size element.  Linux reports the 
actual file size, not the storage size, which you can get by asking to 
see the number of blocks used to store the file (ls -ls).


I wrote a small perl script which returns the bytes read when a file is 
read from the disk and it, too, agrees with the filesize and header 
sizes.  In Windows, the actual filesize is also returned by filesize and 
stat, not the size on disk (filesize uses stat).   Also, in the PHP 
manual, the fread example uses filesize to set the number of bytes to read:

|contents = fread($handle, filesize($filename));

|The point of this is to read in the exact number of bytes for the file, 
not the entire size of the file's storage on disk which would contain 
garbage.  This has to work on both windows and linux.


Here's the perl script:
   use strict;
   use Fcntl;
   sysopen (FH, "index.htm", O_RDONLY);
   my $buffer;
   my $len = sysread(FH, $buffer, 8192,0);
   print $len,"\n";

If you are really anxious about size you can exec out to this script and 
get the file size.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/




Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Myron Turner

Myron Turner wrote:

Tijnema ! wrote:

On 3/10/07, Németh Zoltán <[EMAIL PROTECTED]> wrote:

2007. 03. 10, szombat keltezéssel 12.42-kor Riyadh S. Alshaeiq ezt 
írta:
> Actually if right click on any file or folder on a machine you 
will see

that
> there are two values (Size on disk & Size). Files and folders are 
stored

on
> the disk in what is called clusters (a group of disk sectors). 
Size on

disk
> refers to the amount of cluster allocation a file is taking up, 
compared

to
> file size which is an actual byte count.
>
> As I mentioned before what I want is a function for getting the 
result

for
> the Size no for Size on Disk

okay then what about this?




Th

I wrote a small perl script which returns the bytes read when a file 
is read from the disk and it, too, agrees with the filesize and header 
sizes.  In Windows, the actual filesize is also returned by filesize 
and stat, not the size on disk (filesize uses stat).   Also, in the 
PHP manual, the fread example uses filesize to set the number of bytes 
to read:

  ||
Here's the perl script:
use strict;
use Fcntl;
sysopen (FH, "index.htm", O_RDONLY);
my $buffer;
my $len = sysread(FH, $buffer, 8192,0);
print $len,"\n";

If you are really anxious about size you can exec out to this script 
and get the file size.


--
  
Sorry the above version of the script was hard-coded for a small test 
file.  Here's the general version:


# get_len.pl
use strict;
use Fcntl;
sysopen (FH, $ARGV[0], O_RDONLY) or die "\n";
my $buffer;
my $bytes_read = 0;
my $offset;
while($bytes_read = sysread(FH, $buffer, 8192, $offset)) {
$offset+=$bytes_read ;
}
print $offset,"\n";

From an exec() you'd call it with the file name:
  perl get_len.pl 
$len = exec("perl get_len.pl $filename");

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Myron Turner


Tijnema ! wrote:


I'm not very familiar with PERL, so will this work with remote files?
As it seems that you are just reading from local hard drive...

Tijnema
It has to be on the machine from which the pages are being served. 

There have been several workable suggestions for different 
possibilities.  I think it would help if you gave the context for this. 
Are these pages on your own web site?   Are you downloading pages from 
third-party web sites using the browser?  Are you using the command line 
to download pages from other servers?


Here is a script which will get the headers for any file you can 
download from the web:


\n";
} else {
   $out = "HEAD http://www.example.org/any_page.html / HTTP/1.1\r\n";
   $out .= "Host: www.example.org\r\n";
   $out .= "Connection: Close\r\n\r\n";

   fwrite($fp, $out);

   $header = "";
   while (!feof($fp)) {
   $header .=  fgets($fp, 256);
   }
   fclose($fp);
   echo $header;
}
?>

In response you will get the headers:

HTTP/1.1 200 OK
Date: Sun, 11 Mar 2007 14:57:54 GMT
Server: Apache/2.0.51 (Fedora)
Last-Modified: Sun, 11 Mar 2007 13:00:03 GMT
ETag: "10eb0036-4d1-3c2bbac0"
Accept-Ranges: bytes
Content-Length: 1233
Connection: close
Content-Type: text/plain; charset=UTF-8


This includes the content-length, which is what you want.  This script 
will download only the headers.


You will not get a content-length headers for php files, since they are 
in effect scripts and their length is not know in advance.  The same 
holds true for files which contain SSI.

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Myron Turner
I think we've been talking to ourselves.  The guy with the original 
question seems to have folded his hand and gone home.



This is exactly what my script also did, get the content-length from the
header.
But i don't see what the actual problem is, there have been a lot of
solutions around here but they are all wrong?

Tijnema


--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Why won't this query go through?

2007-03-11 Thread Myron Turner

Jochem Maas wrote:

Tijnema ! wrote:
  

On 3/11/07, Mike Shanley <[EMAIL PROTECTED]> wrote:


Hi,

I am just not understanding what I could have possibly done wrong with
this query. All of the variables are good, without special characters in
any sense of the word... So why isn't it importing anything?

Thanks!

$q = "INSERT INTO

`visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)

   VALUES ('".$username."',
   '".md5($password1)."',
   '".$email."',
   '".$firstname."',
   '".$lastname."',
   '".$birthdate."',
   '".$verifythis."');";
  
Haven't you converted all of your columns to literals: 'username', etc, 
which should be plain username?


I find it's clearer to use the heredoc syntax:

$query= <

Re: [PHP] xml parsing

2007-03-12 Thread Myron Turner

Richard Lynch wrote:

I don't think that's valid XML, because you are mixing your content
with your XML tags in a way that will confuse the two...

If you can FIX the XML by using the CDATA stuff, or htmlentities
encoding the HTML or something, that would be best.

If you are STUCK with this bogus XML, you could probably write your
own parser for something this simple/small in about an hour using
http://php.net/strtok and friends...


On Sun, March 11, 2007 7:38 pm, Marije van Deventer wrote:
  

I have been trying to parse this xml, and want to use it with
childnodes  and , but sofar due to the  and  and
 elements no luck. How can i do this in a simple way ???



 
  Algemeen
  a
 
 
  1-Atmosfeer
  
  a
  bbb
  ccc
  dd
  qqq
 
 
  Betrouwbare drukcabine
  
 




  
I put the above xml text into an xml editor and it tests as valid, 
despite its raggedness, and I did manage to get it to parse with 
simplexml, using the following:


$string = the above xml;

$xml = simplexml_load_string($string);

foreach($xml->Item as $item ){
  trim($item->Label);
  echo $item->Label . "";
  if(isset($item->Tekst)) {
   trim($item->Tekst);
  echo $item->Tekst . "";
  }
}







--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] $35 to the first person who can do this XML-parsing PHP script

2007-03-12 Thread Myron Turner

Richard Lynch wrote:

For something that simple in PHP4, I didn't even bother with the
50-line expat lib solution...

A couple preg matches, or even just strtok and call it done...

//assume file_get_contents is too "new"...
//probably wrong, but be safe
$xml = implode('', file('www.librarytools.com/events/sampledata.txt'));

preg_match_all('|.*([^<]*).*(f
n="eventnextoccurrencedate">([^<]*))?|msiU', $xml, $eventdata);

var_dump($eventdata);

I probably got the regex wrong -- I usually do...
  
Of course, there are all kinds of hacks which can be used for simple 
situations--even sometimes complex situations.  I recently wrote a Perl 
script for a complex screen-scraping task which by-passed all of Perl's 
standard parsers and used Perl's regular expression facilities.  But 
then I know how to use Perl's parsers if I have to, as well as when not 
to use them if I prefer.  So now Rob Gould, who asked the original 
question, knows a few things about the expat parser which he didn't 
understand before and will be able to use it in the future. That seems 
to me worthwhile, and more useful in the long run than scratching out a 
few regular expression hacks that have limited local applicability. 


Myron Turner

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



Re: [PHP] 2 errors I can not understand

2007-03-13 Thread Myron Turner

Matt Carlson wrote:
I think you have an issue with the line 


while($d<$s) when it comes to the number 3.

$d will NEVER be < $s if $s = 3.

I think you want $d<=$s??  Or maybe a switch for the number 3?

- Original Message 
From: Jonathan Kahan <[EMAIL PROTECTED]>
To: php Lists 
Sent: Tuesday, March 13, 2007 4:30:45 PM
Subject: [PHP] 2 errors I can not understand

Hi all,

Please see my output  below followed by the code. I have been trying for 
some to figure out why


1) I can not get a line feed to work in the web page that i am using to 
display the output as I am not running from the commad line


2) Why my loop is only executing 3 times when i want it to execute 50

Any help would be greatly appreciated.

Jonathan

The next line is all that displays on the output html page:

Output: The number 0 is 0 The number 1 is 0 The number 2 is 1 The number 3 
is 1


php script:







"tjon2.php" 78L, 447C written

  

You have an infinite loop going:

  if ($s%$d=0)  should be:   if ($s%$d==0)
--otherewise your loop keeps going:
 while ($d<$s)
since $d (0) will be less and $s


--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] 2 errors I can not understand

2007-03-14 Thread Myron Turner

Richard Lynch wrote:

On Tue, March 13, 2007 6:04 pm, Jonathan Kahan wrote:
  

This did fix the problem but I am amazed that

$s%$d=0 would be interpereted as a statement assigning d to 0 since
there is
some other stuff in front of d... I would think that would produce an
error
at compile time since $s%$d is an illegal variable name. Normally when
my
php script errors at compile time nothing will display to the screen.



You still have not correctly puzzled out what $s % $d = 0 is doing...

The = operator takes precedence, and $d is set to 0.
  
But why?  According to the manual, the modulus operator has precedence 
over the equals!  So shouldn't this expression  resolve to:

  ($s % $d) = 0
which gives an error?

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] 2 errors I can not understand

2007-03-14 Thread Myron Turner

Robert Cummings wrote:

On Wed, 2007-03-14 at 12:57 +0100, Tijnema ! wrote:
  

On 3/14/07, Myron Turner <[EMAIL PROTECTED]> wrote:


Richard Lynch wrote:
  

On Tue, March 13, 2007 6:04 pm, Jonathan Kahan wrote:



This did fix the problem but I am amazed that

$s%$d=0 would be interpereted as a statement assigning d to 0 since
there is
some other stuff in front of d... I would think that would produce an
error
at compile time since $s%$d is an illegal variable name. Normally when
my
php script errors at compile time nothing will display to the screen.

  

You still have not correctly puzzled out what $s % $d = 0 is doing...

The = operator takes precedence, and $d is set to 0.



But why?  According to the manual, the modulus operator has precedence
over the equals!  So shouldn't this expression  resolve to:
  ($s % $d) = 0
which gives an error?
  


  

Might it be that it generates only an error in specific error levels?



Simple proof of precedence problem:



Cheers,
Rob.
  
This illustrates what in fact happens.  But I still don't understand 
why, since, given the precedence of these operators, the = should be 
applied after the modulus.  The expression should resolve to ($x % $y) = 
5 and not to $x % ($y=5).  Or shouldn't it?


--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Regex error

2007-03-14 Thread Myron Turner

jekillen wrote:

Hello;
The following regex:

ereg("id='$m[1]'>", $groups, $m1);


is causing the following error:

Warning: ereg() [function.ereg]: REG_ERANGE in _proc.php on 
line 81


Can someone tell me what this means?

What I am trying to do is pick out some info from an xml tag the is 
id'd by

$m[1] ( a match from a preceding regex. This regex is only supposed to
be applied if there is an $m[1] match. This happened without the
dot (.) and forward slash escaped in the uspace=' etc ' section. I used
back slashes to see if that made a difference, it does not. I have gotten
a little hazy on what needs to be escaped in character classes.

 I have written a number of
similar regexs in the same collections of scripts and I can not see what
this one is complaining about.
php v5.1.2, Apache 1.3.34, FreeBSD v6.0
Thanks in advance
Jeff K



What is this part of the regex supposed to be doing: [a-z0-9-\.\/] ?
Your problem is this: 0-9-, which causes a bad range error.




--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] 2 errors I can not understand

2007-03-15 Thread Myron Turner

Ford, Mike wrote:

On 14 March 2007 22:52, Richard Lynch wrote:

  

On Wed, March 14, 2007 6:52 am, Myron Turner wrote:


Richard Lynch wrote:
  

On Tue, March 13, 2007 6:04 pm, Jonathan Kahan wrote:
The = operator takes precedence, and $d is set to 0.



But why?  According to the manual, the modulus operator has
precedence over the equals!  So shouldn't this expression  resolve
to:($s % $d) = 0 which gives an error?
  

Ya got me there.

I hadn't even checked the precedence list before answering.

Unless somebody has a rational explanation, I think this should be an
error... 



When a similar anomaly involving the ! operator was reported 
(http://bugs.php.net/bug.php?id=17180), the response was that PHP is "smart" 
about such things and invokes the DWIM principle to silently alter the precedence of = in 
certain situations.  This resulted in the addition of a note to the end of the operator 
precedence page at 
http://uk2.php.net/manual/en/language.operators.php#language.operators.precedence, but it 
seems to me that this is too specific to the ! operator and should be generalized.  In 
fact, I'd completely forgotten that I suggested as much at the end of the bug report -- 
but this hasn't been taken up, so maybe a bunch of you want to re-activate the bug report 
and support my suggestion??

Cheers!

Mike

  
I've submitted a bug report with respect to this: 
http://bugs.php.net/bug.php?id=40820.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: Getting last record ID created from DB

2007-03-17 Thread Myron Turner

Colin Guthrie wrote:

Philip Thompson wrote:
  

For auto increment values, you don't have to specify the id. For example:

INSERT INTO t_users (f_name, l_name, e_mail, b_date, pic)
VALUES ('$f_name', '$l_name', '$e_mail', '$b_date', null);

Then to find the latest entry:

SELECT user_id FROM t_users ORDER BY user_id DESC limit 1;



This is not the cleanest way and some databases do not actually
increment auto id fields (e.g. they could fill in the blanks from
previous deletes etc.).

Much better is to use the function in the MySQL API to get the insert id
or if you really must use SQL, just run "SELECT LAST_INSERT_ID();" which
does much the same thing.

Col

  
My own knowledge of mysql is about 5 years old and never really used.  
But I was recently asked to do something that required some mysql 
(noting too much, fortunately for me), so I've been doing some reading 
and am interested in questions that come up on the list.


An earlier post called attention to a concurrency problem.  Wouldn't 
getting the last inserted ID from LAST_INSERT_ID()
suffer from the same limitations as any of the other solutions which do 
a select to get the last ID?  I assume if you are completely in control 
of the database, you could create a lock file using flock() and remove 
the lock once the Id is retrieved using any of these methods.  I guess 
what I'm wondering is whether the simplest suggestion is the one that 
would use the email address as a condition in the WHERE clause to 
extract the ID?


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: Getting last record ID created from DB

2007-03-17 Thread Myron Turner

Robert Cummings wrote:

On Sat, 2007-03-17 at 09:43 -0500, Myron Turner wrote:
  

An earlier post called attention to a concurrency problem.  Wouldn't
getting the last inserted ID from LAST_INSERT_ID()
suffer from the same limitations as any of the other solutions which do
a select to get the last ID?


No, it's a MySQL specific feature that is atomic with the insert and so
you are guaranteed that the the returned ID is the exact automatic ID
associated with the most recent INSERT for the connection handle.
Unfortunately auto increment is MySQL specific and so it isn't
transferrable to other database engines.
  

The problem is if the ID returned is not somehow linked to the transaction
which inserted the row. If you have an insert followed by a select to
retrieve the ID, in the interrum, another user may be created by another
process and you will retrieve the wrong ID. 



I don't believe this is an issue for MySQL. The last inserted ID isn't
stored for the database table, it's stored for the connection to the
database. As such there's no race condition unless the developer does
something silly, like issue another insert over the same connection
before requesting the previous last inserted id. Just to be sure though
the following is from the MySQL online documentation:


For LAST_INSERT_ID(), the most recently generated ID is maintained in
the server on a per-connection basis. It is not changed by another
client. It is not even changed if you update another AUTO_INCREMENT
column with a non-magic value (that is, a value that is not NULL and not
0). Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously
from multiple clients is perfectly valid. Each client will receive the
last inserted ID for the last statement that client executed.


http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

Cheers,
Rob.
  

Thanks.  Very interesting, and makes a lot of sense.

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: PHP code only works on 1 server

2007-03-19 Thread Myron Turner

PHP wrote:

Dear All,
I wrote a simple PHP 404 handler (index.php)(see the code below) to catch
missing pages for instance. But it only works on 1 server and not the other.

This is the server where it works:
My Server:
http://www.orbitalnets.com/support/info.php

This is the server where it won't work (which is the server where it should
work):
Setarnet:
http://www.kabga.aw/info.php

Could it be the version difference? How should it be coded to work on all
php servers?



Here is the code of the index.php file.

http://www.kabga.aw/nl/index.php\";> ";
 $errormsg .= "";
 $errormsg .= "404 File not foundmailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]";
 $errormsg .= " Tel: +297 582-4455Fax: +297 582-2018";
 $navsignthing = "$page";
 $extension = "php";

if(file_exists("$navsignthing.$extension"))
{
include "$navsignthing.$extension";
}
elseif($navsignthing=="")
{
include "default.$extension";
}
else
{
echo "$errormsg";
}
?>


Please let me know,

Dwayne Heronimo


This isn't a php issue but an apache issue.  Have you checked to make 
sure that apache redirects the 404 to your custom error message?


 http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Amazon AWS + SimpleXML

2007-03-20 Thread Myron Turner

Brad Fuller wrote:

Hey guys,

I'm having trouble trying to parse XML results from an Alexa Web information
service from amazon.com, using SimpleXML.


  


I found a site which deals with handling namespaces in SimpleXML.  That 
and the nested tags are probably what are giving you trouble,   This is 
the url:

   http://www-128.ibm.com/developerworks/xml/library/x-simplexml.html

You might also want to look at XML_PullParser.  I've written a script 
which does the job:

 http://mturner.org/pullParser/amazon.phps
The result is:
   http://mturner.org/pullParser/amazon.php

You can download the class files at  http://www.mturner.org/XML_PullParser/
If  you decide to use it, download the most recent version, which is 1.3.2.

--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: Keep the PHP list ON TOPIC! (was: [PHP] MYSQLyog)

2007-03-21 Thread Myron Turner

Jonathan Kahan wrote:

Understood.

I will think harder next time before posting.

- Original Message - From: "Jim Moseby" 
<[EMAIL PROTECTED]>
To: "'Jochem Maas'" <[EMAIL PROTECTED]>; "Jonathan Kahan" 
<[EMAIL PROTECTED]>

Cc: "Stut" <[EMAIL PROTECTED]>; 
Sent: Wednesday, March 21, 2007 9:17 AM
Subject: Keep the PHP list ON TOPIC! (was: [PHP] MYSQLyog)





so that make's your totally offtopic question okay then does?
I suppose you condone murder also because, heck, others have
done it before, right?

> And yes in my mind this is part of  PHP in that PHP
> interacts with MYSQL and thus this has a bearing on my
ability to write
> PHP programs in the future.

your mind seems rather clouded or just plain narrow.
you can't connect to a mysql server using some window gui app
... there is
no php there, period.

> I have already written a few PHP programs
> without using the mysql functions which yes are a part of PHP.

technically the mysql wrapper functions are part of a php extension.
there are plenty of people who run php without the mysql
extension btw.

> This is
> an email support group-I am not attempting a masters thesis here.

this is general php support list - please do come back when
you have trouble
with mysql_connect(), mysql_query() and the like.

otherwise go get your help from the correct source, I'm sure there is
plenty to be found at mysql.com for example (or webyog.com???).



Put another (kinder? gentler?) way:

While the fine folks of the PHP General list might be able to make a 
pretty
good guess as to the solution to your non-PHP problem, you would find 
much
better, quicker, more accurate (and less prickly) advice from the 
MYSQLyog

or MYSQL support lists.

The more we can keep the topic focused on PHP here, the better the 
perpetual

archive will be for PHP knowledge seekers going forward.

JM




I've been following this thread on and off, because I found the 
unnecessarily hostile tone of the initial response so off-putting.  But 
while this rather small infraction of OT code, which can in fact be 
defended, had been taking place, at the same time on this list an 
ongoing, extensive discussion of the relative merits of various 
databases has been going on and yet no one has said a word.  My guess is 
that Jonathan, as new to the list, was being selectively picked on, 
while the guardians of the list looked the other way with respect to the 
other thread because some of the people involved there are long time, 
valuable contributors, with lots of weapons at their disposal.  I could 
be wrong, of course. But I'm certainly not wrong to believe that the 
remedy for a foul mouth is soap and water.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: Keep the PHP list ON TOPIC!

2007-03-21 Thread Myron Turner

Jochem Maas wrote:

I would have made a similar comment - but I have soap stuck between my teeth 
atm :-P
  

Just use a little of that saliva that you've been wasting on spitballs. ;-)

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Random Unique ID

2007-03-21 Thread Myron Turner

Mark wrote:

[EMAIL PROTECTED] wrote:


Hello,

I want to add a random unique ID to a Mysql table.  Collisions
are unlikely but possible so to handle those cases I'd like to
regenerate the random ID until there is no collision and only
then add my row.  Any suggestions for a newbie as to the right
way to go about doing this?

Best,

Craig

.

I suggest looking into a GUID sort of thing, it is all coded for you and it
works just like you want.


If you are running Linux, you can get this using:
   $GUID =  exec("uuidgen");
--

_________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Question before upgrading to 5

2007-03-22 Thread Myron Turner

Jochem Maas wrote:

Jake McHenry wrote:
  

I don't need them running parallel, only both installed



I think you missed the point. you would have 2 apaches running, that is correct
but the trick is to set it up so that they use the same document roots
for each site that you are trying to convert.

the beauty of this is that you can literally run the same site in php5 and php4
simulaneously with urls something *like*:

php4.mydevsite.com
php5.mydevsite.com  (ProxyPassed to 'inner' apache)


were HOSTS file contains:

127.0.0.1 php4.mydevsite.com php5.mydevsite.com

and both outer and inner apache's use the same docroot for the given site.

obviously it's just one way of setting up a comfortable dev environment - as 
long
as you have something that allows you to doo your tihng without to much pain 
then thats
the main thing :-)

  
I've handled this by having the second installation of Apache listen on 
a different port.  The default is of course 80, so the directive reads:

  Listen 80
But the second install can listen on, for instance, 8080
 Listen 8080

Then you can access the site, using the same urls, but with the 8080 port:
http://www.example.com:8080/somepage.html

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] usage of flock

2007-03-23 Thread Myron Turner

Richard Lynch wrote:

On Fri, March 23, 2007 7:52 pm, Yvan Strahm wrote:
  

I am confused with the flock function and its usage. I have jobs which
are
stored in a database, these jobs are run by a series of job_runners
scripts
but sometimes the job_runners stop ( server or php crash-down). So i
put a
job_controller in crontab to check  regularly if the  runners run. But
after
a while I have a bunch of job_controller running, so to avoid that I
tried
to use flock.

I try to put this in the job_controller:

$wouldblock=1;
$f=fopen("controller.lock", "r");
flock($f, LOCK_EX+LOCK_NB, $wouldblock) or die("Error! cant lock!");

hoping that as long as the first job_controller run or don't close the
file
handle, a second job_controller won't be able to lock the
controller.lockfile and die, but it didn't work.

I also try this:

$wouldblock=1;
$f=fopen("controller.php", "r");
flock($f, LOCK_EX+LOCK_NB, $wouldblock) or die("Error! cant lock!");

hoping the first job_controller will lock it-self, but it didn't work.

I also thought of writing in the lock file the PID of the first
job_controller and then compare it and if it doesn't match then die,
but my
main concern is , if the server crash down the "surviving" lock file
will
prevent any job_controller to start.

So how could prevent multiple instance of the same script? Is flock
the best
way?



You can do it with flock, but then you end up sooner or later with a
locked file from an "exit" or killed script, and then you have to know
to remove locks older than X minutes.

You could also just do a "mkdir" for your lock, and check its
filemtime.  You could even use "touch" within loop of the script to
make sure the script is still going, and safely assume that any lock
older than X seconds is stale and can be ignored/removed.
  
I've never used locks in PHP, but have used them in Perl.  In Perl a 
lock is automatically released on exit or when the locked file is 
closed.  Is that not the same in PHP?  According the the man page for 
the C version of flock, it too releases the lock on close and C's exit 
closes all streams.  So, Perl is consistent with that.  Just wondering 
for myself it this isn't the case with PHP, in case I ever  want to use 
a lock.


It's not clear to me from the original question, Yvan, whether you are 
able to get any lock at all.  That is, if you are using LOCK_NB and a 
lock is already on the locked file, then the lock will be refused and 
the call will return immediately without a lock.  So, the only way to 
use LOCK_NB is in a loop.  Generally, this is not recommended, because 
in the time the loop gets back to making a second call, another file 
might have gotten the lock.  However, in your case this might not 
matter, since you are the only one sending out these job controllers, 
and eventually all your processes will have had a chance at the lock file.


On the other hand, if you use LOCK_EX, the call will block until a lock 
is available.  Again, in your case this might not matter either.  The 
danger here is that you will get a process that doesn't shut down.  You 
can deal with this by setting an alarm which is caught using a signal 
handler that can exit the process.


If you use LOCK_NB with a loop, you can also break out of the loop and 
exit after a time as well. You'd probably want to use sleep to time your 
loop, not a counter, since the counter might swallow up cpu.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] usage of flock

2007-03-27 Thread Myron Turner

Richard Lynch wrote:

On Fri, March 23, 2007 10:34 pm, Myron Turner wrote:
  

I've never used locks in PHP, but have used them in Perl.  In Perl a
lock is automatically released on exit or when the locked file is
closed.  Is that not the same in PHP?  According the the man page for
the C version of flock, it too releases the lock on close and C's exit
closes all streams.  So, Perl is consistent with that.  Just wondering
for myself it this isn't the case with PHP, in case I ever  want to
use
a lock.



It is the case, just as in C or Perl, that it's SUPPOSED to shut down
nicely and remove the lock...

When, not if, when, something goes terribly wrong, and you manage to
segfault PHP/Apache, do you want to have to remember to manually nuke
the flock somehow, or do you just want to code it from the get-go to
ignore locks older than X time? :-)

No matter how carefully you program your locks, sooner or later,
you'll have to have some "meta" programming about the locks to deal
with an inconsistent state of locks.

At least, that's been my experience so far...

  
It is something to think about.  I've never had this problem but 
possibly because the sites haven't been high traffic enough.


Thanks,

Myron

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



Re: [PHP] using for loop in function

2007-03-28 Thread Myron Turner

Richard Kurth wrote:

   The function below will create a group of checkboxes it will also check
the checkbox that is stored in the table field that is in $select_value this
works fine if there is only one value in the variable but if there is more
stored like 1,2,3,4 it will not work. I am trying to figure out how to use
the following for loop to add the number to each checkbox and if they match
mark the checkbox checked
 
 
 $ExplodeIt = explode(",",$select_value,",");

$Count = count($ExplodeIt);
for ($i=0; $i < $Count; $i++) {
  }

  


$select_value   = "1,2,3,4";
$ExplodeIt = explode(",",$select_value,",");

Using print_r(), you will get
   Array
   (
   [0] => 1,2,3,4
   )
count($ExplodeIt) = 1

$ExplodeIt = explode(",",$select_value);
Using print_r(), you will get:
   Array
   (
   [0] => 1
   [1] => 2
   [2] => 3
   [3] => 4
   )
count($ExplodeIt) = 4



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] PHP 5.2.1: Some scripts are being parsed, but most aren't

2007-03-28 Thread Myron Turner

Mario Guenterberg wrote:

On Tue, Mar 27, 2007 at 10:22:40PM -0700, Eddie wrote:
  

Hi all,

Previously, I had installed Apache 1.3.37 with PHP 5.2.1 as
a static module on Ubuntu 6.06. I am having a problem where,
for some reason, some of my PHP scripts just show source
code, while some are parsed.



Hi...

I have a problem something similar. Any scripts would be parsed, any
would be downloaded in fireofx 2.x. I use Ubuntu 6.10. My solution
is to start the ancient Mozilla browser, with this browser works
everything fine. I think it is a firefox problem?! My server is
apache 2.0.55 with php 5.2.1.

Greetings
Mario

  
It's hard to see how this could be a browser issue.  Firefox does not 
parse the scripts.  The scripts are parsed on the server, under Apache.  
The server outputs the result of the parsing and the browser displays 
the result. 


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/


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



Re: [PHP] PHP 5.2.1: Some scripts are being parsed, but most aren't

2007-03-28 Thread Myron Turner

Zoltán Németh wrote:

2007. 03. 28, szerda keltezéssel 14.42-kor Mario Guenterberg ezt írta:
  

On Wed, Mar 28, 2007 at 07:20:37AM -0500, Myron Turner wrote:

It's hard to see how this could be a browser issue.  Firefox does not 
parse the scripts.  The scripts are parsed on the server, under Apache.  
The server outputs the result of the parsing and the browser displays 
the result. 
  

I know that the browser does not parse the scripts. But what the
hell is the problem? I have changed the apache log settings to debug 
and nothing to see in the log files. The amusing of this is the

old mozilla works fine with the same script. Firefox pop up a download
window. The script is well formed,  tags are included. I
would not be surprised when I see the source of the script in
firefox. But a download window???



the download window is maybe because of incorrect content-type headers.
it is possible that the older browser does not take care about that
header, so the content is displayed ok, but the newer browser reads the
header, cannot interpret it and so offers the download window

check out what headers are the script is sending out

greets
Zoltán Németh

  

The problem is very irregularly. Sometimes the effect steps on new
scripts, sometimes on old scripts that worked before. 


Greetings
Mario




  


I think you have to keep in mind that the headers would not affect the 
actual content being sent to the browser from the server.  If the script 
is parsed as php on the server, it will be sent as text/html to the 
browser and displayed as parsed.  But if the server does not parse the 
script then the browser will receive a copy of the script itself and 
depending then on whether the browser recognizes the content-type as 
displayable, it will either display it or ask if you want to download it.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] crontab, PHP and MACOSX

2007-03-28 Thread Myron Turner

Yvan wrote:

Hello all,

I don't know if it's the correct list, but as a php script is involved

I try to start a set up a crontab job with crontab -e, which should start a php 
script:

*/10*   *   *   *   cd /Users/yvan/Sites/est-pac/ ; 
/usr/bin/php /Users/yvan/Sites/est-pac/controller.php

but nothing happens, and in the /etc/crontab or in /private/etc/crontab the job 
is not listed.
As I am using Mac OS 10.4.9, should I use launchd? or does someone use crontab 
with a mac? I try a GUI application called CronniX to setup the job but without 
success.
Any hints? 


Thanks in advance for your time and help.

cheers
yvan

  


It wouldn't appear in /etc/crontab, which is a system level file.  My 
Mac is being repaired but aren't /etc and private/etc the  same directory? 

Check your mail by typing mail and reading your mail.  If there's an 
error it should/may be reported there (again I'm not sure about OS X).  
Otherwise, or in addition, check your system error logs.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Gnome and MIME types

2007-03-30 Thread Myron Turner

Nathan Ziarek wrote:

Hmmm. This may have nothing to do with it, but, running a command I
know doesn't exist (say "hghswks") at the command line tells me
"-bash: hghswks: command not found"

When I run that same command through exec(), I get nothing back.

The plot thinkens?
The return value to exec is the last line of the command's output.  The 
error message you get at the command line is from bash, not from the 
bogus command.  You can pass in a final parameter and get the status but 
it won't tell you much from a bogus command.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Parsing database variables

2007-03-30 Thread Myron Turner

Jake McHenry wrote:

thought about that, I would need to do one ereg for each variable then
correct? as of right now, there are 0 variables in the first field, and 17
in the second...  so it would be 17 ereg replaces... then if i add or change
anything, possibly more...
 
This will work, but was hoping for an easier way...
 
Jake
 



   _  

From: Daniel Brown [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 30, 2007 5:02 PM

To: Jake McHenry
Subject: Re: [PHP] Parsing database variables



Jake, could you use ereg_replace() to do that?

} 


I split the first field of the ereg_replace() input so that it wouldn't
be read by the function as a variable.


On 3/30/07, Jake McHenry "mailto:[EMAIL PROTECTED]"[EMAIL PROTECTED]> wrote: 

Sorry.. Typos... But that's not the point... I looked the function... Dunno 
how I missed it Thanks... Do you know if eval() has any size limitations

to it? The database fields are about a page each

Thanks,
Jake


  
I would suggest writing a function in which the parameters are passed in 
as references.  In the function itself have set a variables using the 
heredoc syntax, which incorporates the variables, and then return the 
heredoc variable. Coming from Perl, my impulse is to use a reference for 
the return value, but the manual says not to, that PHP is smart enough 
to know how to optimize itself.  Perhaps someone can tell us whether the 
same is true for the parameters.  The manual is mum on that one.



function set_func(&$var1, &$var2 . . . &var17) {
$return_var = RETURNVAR
"this is  $var1 and $var2. . . .";
RETURNVAR ;

return $return_var;

}

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Parsing database variables

2007-03-30 Thread Myron Turner

Myron Turner wrote:

Jake McHenry wrote:

thought about that, I would need to do one ereg for each variable then
correct? as of right now, there are 0 variables in the first field, 
and 17
in the second...  so it would be 17 ereg replaces... then if i add or 
change

anything, possibly more...
 
This will work, but was hoping for an easier way...
 
Jake
 



   _ 
From: Daniel Brown [mailto:[EMAIL PROTECTED] Sent: Friday, March 
30, 2007 5:02 PM

To: Jake McHenry
Subject: Re: [PHP] Parsing database variables



Jake, could you use ereg_replace() to do that?

I split the first field of the ereg_replace() input so that it 
wouldn't

be read by the function as a variable.


On 3/30/07, Jake McHenry mailto:[EMAIL PROTECTED]"[EMAIL PROTECTED]> wrote:
Sorry.. Typos... But that's not the point... I looked the function... 
Dunno how I missed it Thanks... Do you know if eval() has any 
size limitations

to it? The database fields are about a page each

Thanks,
Jake


  
I would suggest writing a function in which the parameters are passed 
in as references.  In the function itself have set a variables using 
the heredoc syntax, which incorporates the variables, and then return 
the heredoc variable. Coming from Perl, my impulse is to use a 
reference for the return value, but the manual says not to, that PHP 
is smart enough to know how to optimize itself.  Perhaps someone can 
tell us whether the same is true for the parameters.  The manual is 
mum on that one.



function set_func(&$var1, &$var2 . . . &var17) {
$return_var = RETURNVAR
"this is  $var1 and $var2. . . .";
RETURNVAR ;

return $return_var;

}

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/


Should be:

$return_var = RETURNVAR
this is  $var1 and $var2. . . .
RETURNVAR ;

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] finding the index name of an associative array

2007-04-01 Thread Myron Turner
Man-wai Chang wrote:
> myarray=array()
> myarray['a']=1
> myarray['b']=1
> myarray['c']=1
>
> Is there an iterative way to find out the array index values ('a', 'b'
> and 'c') of myarray?
>
>   

array *array_keys* ( array $input [, mixed $search_value [, bool $strict]] )

*array_keys()* returns the keys, numeric and string, from the /input/
array.


http://www.php.net/manual/en/function.array-keys.php

-- 

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Question about form submitting

2007-04-03 Thread Myron Turner

Mário Gamito wrote:

Hi,

Sorry for the lame question, but i didn't find a satisfactory answer in
the web.

I have this subscribe form (subscribe.php) and on submit i have to check
for errors:

a) password and password confirmation mismatch;
b) missing filled fields
c) check e-mail validity
d) etc.

My question is how do i make all these possibilities show a different
error message without leaving subscribe.php ?

I know that the for action must be subscribe.php, from there i'm blind
as a bat.

Any help would be appreciated.

Warm Regards
  



--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] PHP4 vs PHP5

2007-04-07 Thread Myron Turner

Travis Doherty wrote:

What about the argument that PHP4 is dead.  It's done.  It's over. 
There is no reason anyone should be using it, less perhaps a lack of

time to tweak scripts for an upgrade from 4 to 5.  Even if that is the
case, get to work :p

"Support for PHP 4 will be dropped at the end of the year, 8 months from
now. So now is the time to start upgrading all your scripts as we won't
be releasing new versions after December 31st, 2007."

http://derickrethans.nl/php_quebec_conference_rip_php_4.php

Travis Doherty

  
This is fine, as long as the newer versions are backwardly compatible.  
If , in particular, if the next version or version 6 does not support 
the PHP 4 object oriented model, it could present real problems for some 
software.  PHP isn't used only for "scripts" but for large projects.  
For example, I just began to configure a DokuWicki installation, writing 
code for various features which are not included in the install.  
DokuWicki uses the PHP 4 object oriented model throughout, and user 
plugins, such as mine, are written to the same model.  DokuWicki 
contains over 300 php files and more than 3 megs of code.  It would be 
no small task to convert such a project over to the PHP 5 OO model. 


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-19 Thread Myron Turner

André Medeiros wrote:

php://stdin perhaps?

On 4/18/07, Justin Frim <[EMAIL PROTECTED]> wrote:

André Medeiros wrote:

> Reading from php://input on a webserver will retrieve the Body of the
> HTTP Request.

Not for me it doesn't.
That only seems to work when the form is submitted as
application/x-www-form-urlencoded.  When the form is submitted as
multipart/form-data, php://input is blank.



You probably could use this small Perl script via exec:

#!/usr/bin/perl
if ($ENV{'REQUEST_METHOD'} eq "POST") {
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}

print $buffer;




--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-19 Thread Myron Turner

Tijnema ! wrote:

On 4/19/07, Myron Turner <[EMAIL PROTECTED]> wrote:

André Medeiros wrote:
> php://stdin perhaps?
>
> On 4/18/07, Justin Frim <[EMAIL PROTECTED]> wrote:
>> André Medeiros wrote:
>>
>> > Reading from php://input on a webserver will retrieve the Body 
of the

>> > HTTP Request.
>>
>> Not for me it doesn't.
>> That only seems to work when the form is submitted as
>> application/x-www-form-urlencoded.  When the form is submitted as
>> multipart/form-data, php://input is blank.
>
You probably could use this small Perl script via exec:

#!/usr/bin/perl
if ($ENV{'REQUEST_METHOD'} eq "POST") {
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}

print $buffer;


If you call this script via exec, it can't return the POST data send
to the PHP script right?

You're right.  It doesn't carry across from Perl to PHP.  As penance, I 
worked out how to do it using PHP:










btw, we are here on a PHP list, not PERL :)

Does this mean you wouldn't use exec or system to run anything but PHP 
scripts?  Or just that you wouldn't talk about it here, under penalty of 
exclusion from PHP heaven?  :)



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-19 Thread Myron Turner
That's not been my experience.  I've tested it with 
enctype="multipart/form-data", since that's what you asked for, though 
the enctype wasn't included in my sample code.  I've run it on PHP 
Version => 5.1.6 (Fedora core 4) and PHP 4.3.11 Fedora core 2.

Here it is on Fedora 2:
   http://www.mturner.org/temp/post_data.php
The code is
   http://www.mturner.org/temp/post_data.phps
That latter is just a symbolic link to the former.

It's possible that there's been a change in 5.2 that changes this 
behavior, or possibly the way the FreeBSD and Windows handle STDOUT.
My little earlier snippet of Perl should work on any system, and so if 
you know any Perl, an elaboration of that would be the way to go. 


Justin Frim wrote:

Sorry burst your bubble, but your solution isn't a viable one in my case.
php://input only works if the form is submitted using 
application/x-www-form-urlencoded.


Take your sample HTML code there and add enctype="multipart/form-data" 
to the  tag, and I'm pretty sure you'll find that php://input 
contains no data.  (Both PHP 5.2.1 running as a CGI on Windows and PHP 
5.2.0 running as an Apache module on FreeBSD exhibit this behaviour.)


And before anyone asks, it *is* a requirement to accept 
multipart/form-data submissions because that's the only way you can 
properly implement a file upload on a web form.





--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-19 Thread Myron Turner

Gregory Beaver wrote:

[21:58]  can you do a file upload without multipart?
[21:59]  Well, if you want to pick a POST apart yourself, sure
[21:59]  set a mime type PHP doesn't understand and it will be
in http_raw_post_data and then you can do whatever you want with it

So the answer is "sort of."  You would have to parse the POST data
yourself, but it is technically a possibility.

  
That was also in the back of my mind when responding.  When file uploads 
first came out and weren't yet handled by the Perl CGI module, we had to 
learn to parse the input stream ourselves.  It's still not clear why 
that should be necessary at this time.  For instance, if it's necessary 
to pass in CGI  parameters at the same time as sending out  a file, the 
parameters can be tacked onto a query string and they will be packed 
into both the $_POST and the $_GET arrays. 


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-19 Thread Myron Turner

Gregory Beaver wrote:

Myron Turner wrote:
  

That's not been my experience.  I've tested it with
enctype="multipart/form-data", since that's what you asked for, though
the enctype wasn't included in my sample code.  I've run it on PHP
Version => 5.1.6 (Fedora core 4) and PHP 4.3.11 Fedora core 2.
Here it is on Fedora 2:
   http://www.mturner.org/temp/post_data.php
The code is
   http://www.mturner.org/temp/post_data.phps



the enctype attribute should be in the  tag, not the submit
.  Put it in  and your php://input will disappear

  
That's what happens when your trying to do too many tings at once. 


Thanks,

Myron

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-21 Thread Myron Turner

Justin Frim wrote:

Richard Lynch wrote:

On Thu, April 19, 2007 10:28 pm, Myron Turner wrote:
 

that should be necessary at this time.  For instance, if it's
necessary
to pass in CGI  parameters at the same time as sending out  a file,
the
parameters can be tacked onto a query string and they will be packed
into both the $_POST and the $_GET arrays.



I've lost track of why the OP needs an md5 or whatever it is of the
raw POST data, but MAYBE using an unknown MIME type and putting all
the other args in the URL as $_GET parameters, would leave them with
only the file itself to be "parsed" which would be pretty minimal
parsing...

  
There exists a mode of HTTP digest authentication where a header 
contains an MD5 hash of an MD5 hash of the POST body (along with a few 
other things that effectively add a salt to the hash, and provide the 
actual username/password authentication).  This is used for "integrity 
protection", to safegaurd against any malicious proxy or "man in the 
middle" attack from altering the form data while it's in transit from 
the authorized user to the web server.


I'm a little lost here though... how can it be possible to put data 
into the URI as well as the POST body?  The request is originating 
from the user-agent, not the server.  Regardless though, the real 
problem with this proposed hack is how, through HTML code, would one 
instruct the user-agent to submit the form using multipart/form-data, 
but without it creating a Content-Type: multipart/form-data header in 
the request!?  This sounds like an impossible task to me.




In one of my early replies to this question, I suggested using Perl.  
But I assume you prefer not to.  However, I have tried putting my head 
around a hack, which does use a small Perl script but which might do the 
trick for you.You use the Perl script in the action attribute of 
your form.  The Perl script saves the entire posted output to a file, 
then it sends back a page which uses Javascript to redirect back to the 
php script, where you can process the file.  You send the file name back 
to the php script from the perl script in the query string of the url.  
Here goes:



' .$_GET['file'] . '';
}
?>



Send this file: 


-

Then the Perl script:

#!/usr/bin/perl
# save.cgi

if ($ENV{'REQUEST_METHOD'} eq "POST") {
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}


print "Content-Type: text/html\n\n";


open FH, "> /var/www/html/d_wiki/upload/tmp.fil";
print FH $buffer;
close FH;

print '';
print 'location = 
</tt><tt>"upload.php?file=tmp.fil;"';

print 'Redirecting to upload.php?file=tmp.fil';


You don't have to know much about Perl here.  The only thing you would 
want to do is find out how to construct a unique temporary file name, 
for the saved file, which you would then probably delete in the PHP 
script after processing with PHP.


Hope this helps.

Myron

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-22 Thread Myron Turner

Richard Lynch wrote:

On Sat, April 21, 2007 10:56 pm, Myron Turner wrote:
  

trick for you.You use the Perl script in the action attribute of
your form.  The Perl script saves the entire posted output to a file,
then it sends back a page which uses Javascript to redirect back to
the
php script, where you can process the file.  You send the file name
back
to the php script from the perl script in the query string of the url.



At that point, why not just have Perl call PHP?

Surely Perl can do something not unlike 'exec' or whatever to run any
shell script you want...

I sure wouldn't do another round trip to the browser and add JS into
the middle of this solution, if it's viable...

Wouldn't work for me, as I can't do Perl.

  
Perl could,  could of course do the whole job.  But since the Original 
Poster was (I assumed) not particularly familiar with Perl,  I was 
essentially providing a Perl script to do the base essentials.  So my 
hack would put him right back into PHP.  If he execs from Perl to a PHP 
script to do the processing, then he would have to  augment the Perl 
script to send back HTML to the browser, and if he can do that he can 
probably stick with the Perl altogether.  Anyway, that was my reasoning.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: how to detect type of image

2007-04-22 Thread Myron Turner

Jonathan wrote:

Alain Roger wrote:

Hi,

In my web application, end user is able to load images (png, jpeg, 
gif,..)

into database.
I would like to know how can i detect automatically the type of image 
(pnd,

jpeg,...) ?
i do not want to check the extension because this is easily faked... 
just by

renaming it.

Does it exist a technique for that ?

thanks a lot,



Is there anything wrong with just using $_FILES['upload_name']['type']?



$_FILES['upload_name']['type'] appears to believe the extension.  Try 
it--upload a file with a misleading extension.


This same question was asked yesterday and the advice was to use
string *mime_content_type* ( string filename)
That doesn't seem to get fooled very easily, though I suppose you could 
fool it if you went to the effort of, say, setting up a fake image 
header, when what you are sending is a time bomb.


M.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] retrieve POST body?

2007-04-23 Thread Myron Turner

Justin Frim wrote:

You are correct, I'm not very familiar with Perl.

If I do go the route of using something else to accept the form data 
and then executing the PHP script, I'd be leaning more toward somehow 
executing the PHP script directly rather then sending back a redirect 
to the user-agent to re-send the request to the PHP script.  Reason 
being that if a file is uploaded, it ends up getting sent twice.  For 
a large file, that's a lot of extra HTTP traffic.
I'm not sure I follow here, because the Perl script would be saving the 
posted file to disk.  It would then send back a redirect with the name 
of the file in the query string of the url, which would point to a php 
script that would then read the file from the disk.  So the file 
shouldn't be sent more than once.  In any event, I do think that at 
least a few of use are agreed that somehow the whole post should be made 
available in PHP.


Good luck with your solution,

Myron


_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Separating words based on capital letter

2007-04-24 Thread Myron Turner

Richard Lynch wrote:

Why rule out PCRE, which is probably the best weapon for the job?

$string = ltrim(preg_replace('([A-Z])', ' \\1', $string));

  

Don't mean to be pedantic, but you left out the '/. . ./':

$string = $string = ltrim(preg_replace('/([A-D])/', " \\1", $string));

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] sorting multi array

2007-04-25 Thread Myron Turner

Jon Bennett wrote:

hi,

I have the following array, which I need to sort by quantity...

Array
(
   [2408] => Array
   (
   [name] => Havaianas Top Pink Crystal
   [size] => 5 (37/38)
   [quantity] => 4
   )

   [3388] => Array
   (
   [name] => Havaianas Brazil Silver
   [size] => 6/7 (39/40)
   [quantity] => 6
   )

   [2666] => Array
   (
   [name] => Havaianas Brasil Black
   [size] => 8/9 (41/42)
   [quantity] => 1
   )

   [3210] => Array
   (
   [name] => Havaianas Margaridas Yellow
   [size] => 5 (37/38)
   [quantity] => 1
   )

   [2552] => Array
   (
   [name] => Havaianas Flash White
   [size] => 5 (37/38)
   [quantity] => 1
   )
)

I need to keep the indexes if poss.

Many thanks,

jon


This works for me:


function cmp($a, $b)
{
   $aq = $a['quantity'];
   $bq = $b['quantity'];

   if ($a == $b) {
   return 0;
   }
   return ($aq < $bq) ? -1 : 1;
}

uasort($data, "cmp");

To reverse the sort order:  return ($aq > $bq) ? -1 : 1;

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Killing a process with php

2007-05-09 Thread Myron Turner

[EMAIL PROTECTED] wrote:
Hi could someone give me examples on how to detect and kill processes 
on linux.
I have a number of scripts running as socketxxx.php these stop and 
start every hour.
But I also need to at the end of each day make sure their dead before 
the next days start.


These processes are also running as root user.

Thanks


One way to do this would be to let the script check itself:

 $end_of_day) {
   exit(0);
   }
   }

   pcntl_signal(SIGALRM, "signal_handler", true);
   pcntl_alarm(300);

?>
Here you set an alarm that checks every 5 minutes to see if the current 
timestamp is greater than the timestamp a minute before midnight.  If it 
is, then exit.  Or set a flag in the signal handler that is accessed 
elsewhere in your script which tells the script that it's time to exit.


--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Need a new shared host with php

2007-05-10 Thread Myron Turner

Afan Pasalic wrote:

Edward Kay wrote:

Al wrote:
I'm looking for a shared host with an up-to-date php5, and one who 
at least tries to keep it relatively current.


Needs are modest.  Just need good ftp access, cgi-bin, shell, etc.

Any suggestions. I'm looking at Host Monster, anyone have experience 
with them?


Thanks...


I use host monster for last year and never had a problem with them. 
Have one account with 8 domains/web sites. None has big traffic.
Though, one of web sites is my personal site with Gallery2 installed. 
When uploading chunk of 10 or 20 images (king size) after is DONE I 
would get a message that I'm using processor more then I could and it 
will keep me out for couple minutes before I can continue. Though, my 
web site is still up, just I can't do anything. And, every time whole 
process was finished without interruption or with error. Strange thing 
(never had similar before) but it doesn't bother me a lot.


Agree with Edward, VPS is better solution - if possible.

I used pair.com for a while. Pricey but VERY GOOD.

-afan


You might want to look at Canadawebhosting.com.  It's located in 
Vancuver and Toronto.  If you pay in $US you get the advantage of the 
higher US dollar.  It's an excellent service for VPS and stand-alone 
server access.  I've used them for both over a period of about 4 years.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] php5 include() problem

2007-05-13 Thread Myron Turner

Tijnema ! wrote:

On 5/13/07, Al <[EMAIL PROTECTED]> wrote:
I've got a cgi file in my cgi-bin folder that I'm calling with 
include(). It worked with php4.


My shared host just upgraded to my server to php5.2.0 and the 
function doesn't work.  I can't tell if the problem is a
php5 or server configuration [which may have changed during the 
upgrade] issue.


If I call the file as a URL directly, it works.
http://www.foo.org/cgi-bin/file.cgi?dir=/test&perms=0755

file.cgi chmods the designated directory's permissions.  It's a cgi 
with a php shebang #!/usr/bin/php


A simple file_exists() shows the file exists OK, TRUE.

I've tried using both syntaxes.

include("/home/foo/public_html/cgi-bin/file.cgi?dir=test&perms=0755");

include("www.foo.org/cgi-bin/file.cgi?dir=test&perms=0755");

Here is the error msg:
> Warning: 
include(/home/foo/public_html/cgi-bin/file.cgi?dir=/test&perms=0755)
[function.include]: failed to open stream: No such file or directory 
in /home/foo/public_html/EditPage/cgi_file_test.php

on line 15

Bottom line:  It appears include() is not working right, for whatever 
reason.


Anyone have any ideas?

Thanks, Al



What the heck are you trying to do?
You want the cgi file to be executed? Or is there PHP code in the cgi 
file?

If you want the first, you should look at exec() or system() or such.
If there's PHP code, there's no sense in passing variables to the CGI
script, and if you remove the variables it will work.

Tijnema


See the examples on this page:  http://ca.php.net/include/
What you probably want to do is to change the cgi script to php and then 
give the full url, incuding http.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] printing out this nested array

2007-05-14 Thread Myron Turner
Jim Lucas wrote:-- 



   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Unknown



Malvolio,12th Night, III.iv

--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] PHP Data Mining/Data Scraping

2007-05-22 Thread Myron Turner



On Sat, May 19, 2007 10:22 pm, Shannon Whitty wrote:
  

I'm looking for a piece of software or coding that will let me post a
form
to another URL, accept the response, search it for a specific
"success"
string and then let me continue processing the rest of my program.



http://php.net/curl

  

I want to accept queries on behalf of my supplier, forward it to them
behind
the scenes, accept their response and display it within my website.

Has anyone had any experience with this?  Is there a simple, basic
utility
to let me do this?

I was kind of hoping I could avoid developing it myself.

As I understand this, you want to create a web page of your own which 
accepts requests for customers who are going to order products from your 
supplier.  You want to have a form on your page which accepts their 
requests, then forward the form data on to your supplier's web site, 
where presumably it will be processed.  Then you want to retrieve the 
response from your supplier's page, and display the result on your own 
web page.  You suggest that the response string for "success" is 
relatively stable and that this string is this what you want to search 
for in the response.


This doesn't sound like a very complicated problem.  You can do this 
either using Ajax or not.  The basic solution is the same.  You have a 
script on the server which accepts the form data from your page and 
re-sends it to the supplier's site.  If your supplier's site accepts 
form data using GET, then you can simply create a url with the form data 
attached in a query string:


http://my.supplier.com?fdata_1=data1&fdata_2=data2

Send this url to your suppler using file_get_contents:

 $return_string =  
file_get_contents("http://my.supplier.com?fdata_1=data1&fdata_2=data2";);


This will return the html file as a string which you can then parse with 
preg_match() for the 'success' string. 

The problem is more involved if your supplier doesn't accept GET but 
only accepts POST.  Then you  have to use either curl or fsockopen to 
post your data.   I've tested the following fockopen script and it 
worked for me:


\n";
} else {
   $out = "POST http://my.supplier.com/form_page.html / HTTP/1.1\r\n";
   $out .= "Host: my.supplier.com\r\n";

   $post = "form_data_1=data_1&formdata_2=data_2";
   $len = strlen($post);
   $post .= "\r\n";   

   $out .="Content-Length: $len\r\n";  
   $out .= "Connection: Close\r\n\r\n";


   $out .= $post;

   fwrite($fp, $out); 


   $result= "";
   while (!feof($fp)) {
   $result .=  fgets($fp, 128);
   }
   fclose($fp);
   echo $result;


}
?>

You have to adhere to the above sequence.  The posted data comes last 
and it is preceded by a content-length header which tells the receiving 
server how long the posted data is.  The returned result is the html 
page returned from your posted request.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] PHP Data Mining/Data Scraping

2007-05-22 Thread Myron Turner

Tijnema wrote:

On 5/22/07, Myron Turner <[EMAIL PROTECTED]> wrote:


> On Sat, May 19, 2007 10:22 pm, Shannon Whitty wrote:
>
>> I'm looking for a piece of software or coding that will let me post a
>> form
>> to another URL, accept the response, search it for a specific
>> "success"
>> string and then let me continue processing the rest of my program.
>>
>
> http://php.net/curl
>
>
>> I want to accept queries on behalf of my supplier, forward it to them
>> behind
>> the scenes, accept their response and display it within my website.
>>
>> Has anyone had any experience with this?  Is there a simple, basic
>> utility
>> to let me do this?
>>
>> I was kind of hoping I could avoid developing it myself.
>>
As I understand this, you want to create a web page of your own which
accepts requests for customers who are going to order products from your
supplier.  You want to have a form on your page which accepts their
requests, then forward the form data on to your supplier's web site,
where presumably it will be processed.  Then you want to retrieve the
response from your supplier's page, and display the result on your own
web page.  You suggest that the response string for "success" is
relatively stable and that this string is this what you want to search
for in the response.

This doesn't sound like a very complicated problem.  You can do this
either using Ajax or not.  The basic solution is the same.  You have a
script on the server which accepts the form data from your page and
re-sends it to the supplier's site.  If your supplier's site accepts
form data using GET, then you can simply create a url with the form data
attached in a query string:

http://my.supplier.com?fdata_1=data1&fdata_2=data2

Send this url to your suppler using file_get_contents:

 $return_string =
file_get_contents("http://my.supplier.com?fdata_1=data1&fdata_2=data2";);

This will return the html file as a string which you can then parse with
preg_match() for the 'success' string.

The problem is more involved if your supplier doesn't accept GET but
only accepts POST.  Then you  have to use either curl or fsockopen to
post your data.   I've tested the following fockopen script and it
worked for me:

\n";
} else {
   $out = "POST http://my.supplier.com/form_page.html / HTTP/1.1\r\n";
   $out .= "Host: my.supplier.com\r\n";

   $post = "form_data_1=data_1&formdata_2=data_2";
   $len = strlen($post);
   $post .= "\r\n";

   $out .="Content-Length: $len\r\n";
   $out .= "Connection: Close\r\n\r\n";

   $out .= $post;

   fwrite($fp, $out);

   $result= "";
   while (!feof($fp)) {
   $result .=  fgets($fp, 128);
   }
   fclose($fp);
   echo $result;


}
?>

You have to adhere to the above sequence.  The posted data comes last
and it is preceded by a content-length header which tells the receiving
server how long the posted data is.  The returned result is the html
page returned from your posted request.



It's a nice script, but you're way better off using cURL, you can
simply pass a PHP array as POST form data.

Tijnema

Thanks. That's good to know.  My experience with these kinds of things 
is with Perl, with which I've done an awful lot of screen-scraping.  But 
I haven't had any actual practical experience with cURL.  I've looked at 
it, but that's all.  Also, I was under the impression that cURL is an 
extension which is not always installed, whereas fsockopen() is a 
built-in. There is one server I sometimes use, a shared server, where it 
isn't installed.  The other servers I use are all independent machines.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] ownership and permissions

2007-06-07 Thread Myron Turner

blueboy wrote:
t: 0131 553 3935 | m:07816 996 930 | [EMAIL PROTECTED] | 
http://www:blue-fly.co.uk



I cannot delete a couple of folders on the server as the have the owner 
'nobody'. All I am doing is making the folders with


mkdir($customer_id, 0755);


Now is there a way to set the ownership when I created the folder. What is 
the appropriate folder levels for securoty (755, 640?)


Thanks,

R. 

  
If they are set to 600, and they were created by the web server, then 
you won't be able to delete them under your own username, using ftp, 
which is why filezilla doesn't work.  But you should be able to write a 
php script which can delete them when it is called from your browser.  
Before you can remove the directory, you will first have to delete all 
the files it holds:


$dir = "images";
foreach($files as $file) {
  unlink ($dir. '/' .$file);
}

remdir($dir);

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] XSLT and DocBook

2007-06-07 Thread Myron Turner

Larry Garfield wrote:
Hi all.  I have a DocBook source[1] that I am processing into XHTML using the 
DocBook XSL[2] toolchain.  That is, XSLT.  I'm not doing a huge amount of 
customization on top of the default setup, either.  Right now, I'm using the 
standard XSLT Java toolchain; Xalan, Xerces, XIncluder, and all of the 
various other Apache projects[3].  The problem is, well, it's Java, which 
means the classpaths and build environment and such break if I so much as 
sneeze at the wrong time.  I'd love to be able to replace it with PHP's XSL 
parser[4], since I actually know PHP and its chances of breaking on every 
other Tuesday are slimmer, but I don't know if it has all of the 
functionality I'd need.  

Specifically, I need multi-file output and support for  
directives.  Right now I'm using the Xalan multi-file output extensions, but 
I'm happy to switch to something else if it means eliminating the huge gobs 
of touchy Javascript I have.  

Does anyone know if that's doable with PHP's XSLT support (circa PHP 5.2, I 
run the server so can install whatever I need)?  Has anyone tried doing this 
before?  It's all offline processing, so performance isn't a huge issue.  
Thanks.


[1] http://www.docbook.org/tdg/en/html/docbook.html
[2] http://www.sagehill.net/docbookxsl/
[3] http://xml.apache.org/
[4] http://us.php.net/manual/en/ref.xsl.php

  

You might get help from comp.text.xml


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Extract specific div element from page

2007-06-15 Thread Myron Turner

Anthony Hiscox wrote:

Hey folks,

I need to pull the contents inside of a specific div out of a page, and
write it to a separate file. In this instance I am taking everything 
inside

of  tags from a wordpress blog, this will give me
only the content and not the menus, or other stuff. I need to do this
because the final document will be converted for viewing on a palm pilot.

Is anyone aware of a simple solution to this problem, short of parsing 
the
entire page and starting when I hit that div opening tag, and stopping 
when

I hit the closing tag? One problem I can see with this method is that I
would have to count divs inside of that div, otherwise I would end too 
early

on.

Any advice would be greatly appreciated.

Peace and Love,
distatica.

What is your relationship to the wordpress blog?  If you have control 
over it, the easiest way to do this is in the browser with Javasacript.  
You can then send the contents to the server, using Ajax if need be, 
where it can be written to the file.


   var content = document.getElementById("content').innerHTML;

Or if the page is being sent back to the server through a form, then put 
the content into a form variable and read that when the page gets back 
to the server, then write it to the file.



--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: Previous and Next Month and Year

2007-06-17 Thread Myron Turner

Keith Spiller wrote:

Hi Vlad,

Thank you for taking the time to help me.

The code:
 $prev_month = date('F Y', mktime(0, 0, 0, 0, date('m') - 6, date('Y')));
 $next_month = date('F Y', mktime(0, 0, 0, 0, date('m') + 6, date('Y')));

 echo "$prev_month  \n";
 echo "$next_month  \n";

Generates:
 November 2006  December 2006
The $prev_month value seems correct,
but the $next_month value should be:
 December 2008

Do you see my mistake?



You've mixed up the parameter positions:

$prev_month = date('F Y', mktime(0, 0, 0, date("m")-6, date("d"), 
date("Y")));
$next_month = date('F Y', mktime(0, 0, 0, date("m")+6, date("d"), 
date("Y")));


See http://ca3.php.net/manual/en/function.date.php for just this example.

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] file_exists, Windows, and EasyPHP

2007-06-18 Thread Myron Turner
I've written a plugin for DokuWiki which uses the following DokuWiki 
function for reading files:


   function io_readFile($file,$clean=true){
 $ret = '';
 if(@file_exists($file)){
   if(substr($file,-3) == '.gz'){
 $ret = join('',gzfile($file));
   }else if(substr($file,-4) == '.bz2'){
 $ret = bzfile($file);
   }else{
 $ret = join('',file($file));
   }
 }
 if($clean){
   return cleanText($ret);
 }else{
   return $ret;
 }
   }

On Linux machines, this seems to behave as you would hope, that is, if 
the file doesn't exist then you get back a null string. In any event, 
none of the users who have installed it on Linux machines have had a 
problem with it.  And I have done several installs myself. But one user 
installed the plugin on a Windows machine and the code fell through to 
$ret = join('',file($file)) even though there was no $file.  The result 
was an error message:


 Permission denied in *E:\Program Files\EasyPHP 
2.0b1\www\dokuwiki\inc\io.php* on line *97


*Line 97 is the join.  So the function is attempting to read a 
non-existent file.


I was just wondering whether there is some difference in the way his PHP 
version handles the @ operator in:


  if(@file_exists($file))

That is, is it possible that by suppressing errors, this expression 
somehow returns true?  And is it a bug?



Thanks.

Myron

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] file_exists, Windows, and EasyPHP

2007-06-18 Thread Myron Turner

Edward Vermillion wrote:


On Jun 18, 2007, at 3:30 PM, Myron Turner wrote:

I've written a plugin for DokuWiki which uses the following DokuWiki 
function for reading files:


function io_readFile($file,$clean=true){
$ret = '';
if(@file_exists($file)){
if(substr($file,-3) == '.gz'){
$ret = join('',gzfile($file));
}else if(substr($file,-4) == '.bz2'){
$ret = bzfile($file);
}else{
$ret = join('',file($file));
}
}
if($clean){
return cleanText($ret);
}else{
return $ret;
}
}

On Linux machines, this seems to behave as you would hope, that is, 
if the file doesn't exist then you get back a null string. In any 
event, none of the users who have installed it on Linux machines have 
had a problem with it. And I have done several installs myself. But 
one user installed the plugin on a Windows machine and the code fell 
through to $ret = join('',file($file)) even though there was no 
$file. The result was an error message:


Permission denied in *E:\Program Files\EasyPHP 
2.0b1\www\dokuwiki\inc\io.php* on line *97


*Line 97 is the join. So the function is attempting to read a 
non-existent file.


I was just wondering whether there is some difference in the way his 
PHP version handles the @ operator in:


if(@file_exists($file))

That is, is it possible that by suppressing errors, this expression 
somehow returns true? And is it a bug?





Are you sure the file doesn't exist? Could it just be that it exists, 
but the permissions are not set correctly?


Ed


I don't really know, since I am depending on the user's feed-back. But 
apparently he hadn't done anything yet with the plugin, so no files 
would have been in that directory. But it's a possibility since the code 
doesn't check for whether the file is readable.


It could just be a Windows issue, but I thought I'd check here, because 
if it's something that others have run into and which I can rectify I'd 
want to do it.


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] file_exists, Windows, and EasyPHP

2007-06-18 Thread Myron Turner

Jim Lucas wrote:

First off, don't jack someone else's thread.

Secondly, I think it might have something to do with the space  in the 
file name.


Try changing all spaces to %20 and see what happens.

$string = str_replace(' ', '%20', $string);

should do the trick

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


Since my own reader isn't threaded I wasn't aware of the threading 
issue.  I'll keep this in mind in the future.


I assume by spaces you are referring to E:\Program Files\.  Well, if a 
php package for windows can't understand its own file system something 
is seriously wrong.  But in fact that's not the case since dokuwiki runs 
on the system and uses io_readFile.


Glad to see you are now crediting Shakespeare.

--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Problem with EXEC and PASSTHRU

2006-10-25 Thread Myron Turner

Matt Beechey wrote:

I am writing a php website for users to edit a global whitelist for Spam
Assassin - all is going fairly well considering I hadn't ever used php until
a couple of days ago. My problem is I need to restart AMAVISD-NEW after the
user saves the changes. I've acheived this using SUDO and giving the
www-data users the rights to SUDO amavisd-new. My problem is simply a user
friendlyness issue - below is the code I'm running -

if(isset($_POST["SAVE"]))
{
file_put_contents("/etc/spamassassin/whitelist.cf", $_SESSION[whitelist]);
$_SESSION[count]=0;
echo "Restarting the service.";
exec('sudo /usr/sbin/amavisd-new reload');
echo "Service was restarted.. Returning to the main page.";
sleep(4)
echo '';
}

The problem is that the Restarting the Service dialogue doesn't get
displayed until AFTER the Service Restarts even though it appears before the
shell_exec command. I've tried exec and passthru and its always the same - I
want it to display the "Service was restarted" - wait for 4 seconds and then
redirect to the main page. Instead nothing happens on screen for the browser
user until the service has restarted at which point they are returned to
index.php - its as if the exec and the sleep and the refresh to index.php
are all kind of running concurently.

Can someone PLEASE tell me what I'm doing wrong - or shed light on how I
should do this.

Thanks,

Matt



--
You have to keep in mind that you are dealing with the difference in 
speed between something that is taking place on the sever and something 
that is being transmitted over a network.  You don't make it clear 
whether this is an in-house site or whether it is used by people at a 
distance.  If the latter, what you describe is not surprising at all.


I've never had a reason to look into how PHP sequences events when it 
pumps out a web page, but it's not unusual for scripts in Perl, for 
instance, to show delays in browser output when doing something on the 
server.  One  consideration would be how long amavisd-new takes to reload.


I'm not very well-informed about hacking and security, but it would seem 
to me that you are taking a risk by giving users root privileges to 
restart amavisd-new.



_
Myron Turner
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Problem compiling PHP 4.4.2 with mcrypt

2006-10-27 Thread Myron Turner

Found this on Google:
http://marc2.theaimsgroup.com/?l=php-install&m=108030891925096&w=2
Then Goto:
 http://mcrypt.hellug.gr/mcrypt/index.html
where it says:

The 2.6.x versions of mcrypt do not include Libmcrypt
The 2.6.x versions of mcrypt need Libmhash 0.8.15 or newer

It has a download facility.






Tom Ray [Lists] wrote:
I have to get a temporary server in place under a tight time frame and 
am using a pre-existing server that wasn't configured really for hosting 
websites. I've upgraded all the services on it like going from Apache 
1.3.x to Apache 2.0.59 and PHP from it's old version to 4.4.2 however I 
need to have mcrypt compiled with PHP and I'm running into a problem.


If I compile PHP without mcrypt I can install PHP without issue. 
However, when I try to compile PHP with --with-mcrypt=/usr/local/mcrypt 
I get the following error:


main/internal_functions.lo -lcrypt -lcrypt -lmcrypt -lltdl -lresolv -lm 
-ldl -lnsl -lcrypt -lcrypt  -o libphp4.la
/usr/lib/gcc-lib/i486-suse-linux/3.2/../../../../i486-suse-linux/bin/ld: 
cannot find -lltdl

collect2: ld returned 1 exit status
make: *** [libphp4.la] Error 1

Now I went back and compiled without mcrypt and looked for that line and 
this is what was there:


main/internal_functions.lo -lcrypt -lcrypt -lresolv -lm -ldl -lnsl 
-lcrypt -lcrypt  -o libphp4.la


I see that along with -lmcrypt not being there neither is -lltdl is 
there something I'm missing? Do I need to have something else installed 
on the box? Normally I haven't had this problem with this. But this is 
an old suse 8.x box that is being used due to time frame issues.


Like I said I can compile PHP without mcrypt, but the project requires 
mcrypt so any help on this would be appreciated.


Thanks!



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: A general UL script

2006-10-28 Thread Myron Turner

Try this:

  if(!isset($_FILES['userfile']['name'])
|| $_FILES['userfile']['error'] == UPLOAD_ERR_NO_FILE) {
 // the file was not uploaded
  }
  else {
 // do your thing,the file has been uploaded
  }

Børge Holen wrote:
When I use a normal single file upload form; both of these statements will 
continue wether my form is empty or not, why?


if(!empty($_FILES)){
do som checking if its a jpg.
if not exit;

if(isset($_FILES)){




--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] str_replace on words with an array

2006-10-29 Thread Myron Turner

I never use this function, since I always use regular expressions, but
according to the manual:
 If you don't need fancy replacing rules (like regular
 expressions), you should always use this function instead of
 ereg_replace() or preg_replace().

So, I assume your problem initially was that you were using regular
expression syntax and this function doesn't accept regular expressions.

Is your aim to get rid strings of all the items in the $noiseArray? Your
 $noiseArray includes the entire alpahabet, so it's no wonder that you
end up with empty strings!

Myron

Dotan Cohen wrote:

On 29/10/06, Alan Milnes <[EMAIL PROTECTED]> wrote:

Dotan Cohen wrote:
> $searchQuery=str_replace( "^".$noiseArray."$", " ", $searchQuery);
Can you explain what you are trying to do with the ^ and $?  What is a
typical value of the original $searchQuery?

Alan



The purpose of the ^ and the $ is to define the beginning and the end of 
a word:

http://il2.php.net/regex

I also tried str_replace( $noiseArray, " ", $searchQuery) but that was
replacing the insides of words as well. And with the addition of the
individual letters, that emptied the entire $searchQuery string!

A typical value of $searchQuery could be "What is php?" or "What is
open source". See this site for details:
http://what-is-what.com

Dotan Cohen

http://technology-sleuth.com/



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Closing a connection to browser without exiting the script

2006-11-02 Thread Myron Turner

I think the Ajax solution that John suggests is the ticket.

I did something like this for a site that books reservations for various 
services. But before the booking can occur, the customer has to get info 
on the various service options, which are returned from a separate 
database server.  This takes time and what the company needed in the 
meantime was a message saying that the query was being processed, please 
wait.  My solution was to print the please wait message to the screen, 
while accessing the database using an Ajax call.  Since with an Ajax 
call you are not waiting for a page to load there's no hour glass or 
clock, etc., and from the user's perspective there's a seamless experience.


I used Perl for my server-side script, but if you prefer PHP you can 
create a CGI script using PHP and run the same process as your original 
PHP page.  Just put #!/usr/bin/php at the top of the script, before the 



Myron

John Comerford wrote:
You could also use an Ajax call from the main window to start the 
processing without opening a second window.


HTH,
 John

Ed Lazor wrote:

Here's another idea:





I have a PHP page that displays a message, and then, performs a very
long operation. Note that it displays the message first.
I do not intend to give some feedback to the user when the operation is
done.

I've seen I can use ignore_user_abort() to prevent the user from
stopping the ongoing operation, but that solves only part of my 
problem.
Because as long as the page is not fully loaded, the mouse cursor in 
the

user's browser is showing a watch.

So ideally, what I would like is to be able to close the connection 
from

the server-side, but without using the exit() function, so my script
keeps running afterwards.






--

_
Myron Turner
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: preg_split

2006-11-03 Thread Myron Turner

1. A preg_ expression has to have the delimeters '/^([^,]+),\s?(.*)/'.

2. Why do you need this complex expression to split at a comma? This 
'/,/' would do the trick.  And even simpler

explode(',', $line);

Also your regex ^([^,]+) asks the perl regex parser to find the 
beginning of a line at which there is one or more instances of NO Comma. 
 That is, [^ ] is a negation, so that [^0-9] means do not match any 
numbers.


Again, the rest of your regex asks for a match for anything else that 
follows 0 or 1 spaces, presumably the rest of the line.
So that any possible split would gobble up everything after the first 
instance in which the beginning of a line did not start with a comma, 
which would mean that you would get null results.


3. Is there a reason why you are using the flag PREG_SPLIT_DELIM_CAPTURE?


Regular expressions are always tricky, so I hope the above comments are 
not totally out to lunch!


Google Kreme wrote:

OK, I have this file:


 $cid=preg_split('^([^,]+),\s?(.*)', $line, -1, 
PREG_SPLIT_DELIM_CAPTURE);


  }
 ?>


the trouble is, $cid is empty.  The actual file has lots of print lines, 
so I know that $lines is an array with each line for $CID_FILE as one 
element of the array and that $line gets the data from a single array 
element correctly.


What I want is for each line to be an array, split at the first comma.  
The regex works in BBEdit, where I can search for


^([^,]+),\s?(.*)

and replace with

\2 \1

and it does the right thing, over and over, so the regex is not the 
issue.  It's something that I am not doing right/understanding in 
preg_split.  I've also tried:


 $cid=preg_split('^([^,]+),', $line);
 $cid=preg_split('^([^,]+),\s?(.*)', $line, PREG_SPLIT_DELIM_CAPTURE);
 $cid=preg_split('^[^,]+,', $line, -1);
 $cid=preg_split('^[^,]+,', $line);

The actual code with the extra printing is here:

<http://akane.covisp.net/~kreme/vonage.phps>
<http://akane.covisp.net/~kreme/vonage.php>

and the sample data is

<http://akane.covisp.net/~kreme/vonage.callers>


--No one ever thinks of themselves as one of Them. We're always one of 
Us. It's Them that do the bad things.



--

_
Myron Turner
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Re: preg_split

2006-11-03 Thread Myron Turner
I see, I miusunderstood, read too quickly, and thought you simply wanted 
to split at the comma.  The suggestion that you use exlode(',',2) makes 
sense to me.  You could do the same with

 preg_split ($pattern, $string, 2)
Or for a more complex regex, there's preg_match, which puts the results 
in an array of matches.  That would to me seem the more logical choice 
if you want to save parenthesized data. But I'm an old Perl programmer 
and there we don't have the extras that PHP gives to preg_split.  So, in 
Perl it's split() for splitting and m// for matching.  Perhaps in 
programming as in art, less is more.


Cheers,

Myron

Google Kreme wrote:




2. Why do you need this complex expression to split at a comma? This 
'/,/' would do the trick.  And even simpler

explode(',', $line);


Because I need to split only at the FIRST comma.



Also your regex ^([^,]+) asks the perl regex parser to find the 
beginning of a line at which there is one or more instances of NO 
Comma.  That is, [^ ] is a negation, so that [^0-9] means do not match 
any numbers.


Yes, and ^([^,]+) means, From the start of the line, get 1 or more 
characters that are not a comma and put them in \01.



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] XML Sending problem

2006-11-05 Thread Myron Turner

Your question interested me for my own work, so I found this url:
   http://www.zend.com/zend/spotlight/mimocsumissions.php

The script, disentangled from the commentary (& with a few of my own 
comments) is as follows:




function post_it($datastream, $url)
{

  $url = preg_replace("@^http://@i";, "", $url);
  $host = substr($url, 0, strpos($url, "/"));
  $uri = strstr($url, "/");

  $reqbody = "";
  foreach($datastream as $key=>$val) {
  if (!empty($reqbody)) $reqbody.= "&";
  $reqbody.= $key."=".urlencode($val);
  }

			// the trick here is to know that the Host 	// header identifies 
the script, not the uri

  $contentlength = strlen($reqbody);
  $reqheader =  "POST $uri HTTP/1.1\r\n".
   "Host: $host\n". "User-Agent: PostIt\r\n".
  "Content-Type: application/x-www-form-urlencoded\r\n".
  "Content-Length: $contentlength\r\n\r\n".
  "$reqbody\r\n";

$socket = fsockopen($host, 80, $errno, $errstr);

   if (!$socket) {
  $result["errno"] = $errno;
  $result["errstr"] = $errstr;
  return $result;
   }

  fputs($socket, $reqheader);

  while (!feof($socket)) {
 $result[] = fgets($socket, 4096);
  }

  fclose($socket);

  return $result;

}

?>

  $data["xml"] = $xml_data; //here of course "xml" will be 
replaced by 	// your own name for the value $xml_data



  $result = post_it($data, 			 
"http://www.example.com/cgi-bin/test/script.php";);


  if (isset($result["errno"])) {
$errno = $result["errno"];
$errstr = $result["errstr"];
echo "Error $errno $errstr";
exit;
  } else {

for($i=0;$i< count($result); $i++) echo $result[$i];

  }

?>

Rosen wrote:
"Unknown Sender" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Hi Rosen,
You can do this for some ways.
The simplest:
1. Send via ftp - http://php.net/ftp
2. Send via scp using ssh2 - http://php.net/ssh2

Regards
Michael

Thanks Michael, but I want if it is possible to do something like "POST" in 
normal HTML language and "say" to the remote script to process XML. And I 
don't have FTP access to remote server. The idea is to working only with XML 
protocol to communicate with remote server. I think I have read something 
like this in the internet, but can't remember where :(


Regards
Rosen




Rosen said:

Hi,

I need to create an XML file and send it to another server, where script 
process the XML.
With creation and processing of XML I don't have a promlems, but how I 
can send XML to the processing script on another server ?



Thanks in advance,
Rosen 



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: fsockopen error messages

2006-11-06 Thread Myron Turner
You may have your host incorrectly set.  I posted an example yesterday 
of how to use sockets with POST under the thread ": [PHP] XML Sending 
problem"



Philip Thompson wrote:

Hi.

I have not dealt much with fsockopen, but after looking at many 
examples, I'm not finding the answers I need. fsockopen is not returning 
anything and I'm trying to find out what the issue is. The error 
messages are not provided and I'm not sure what's going on. Help please!


";
echo "Error: $errstr ($errno)\n";
}
?>

Thanks,
~Philip



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Permanent Links - Blog

2006-11-08 Thread Myron Turner
Extra information, constructed as path info, is returned by the apache 
PATH_INFO environment variable.


Assume this script is called path_info.php:

PATH_INFO




Call it with the following URL:

  http:/my_server/path_info.php/news-item/june3/2005

It will return the following to the screen:

PATH_INFO
/news-item/june3/2005

Myron
Raphael Martins wrote:

Hi,

How do I implement that 
"http://myhost/blog/date/of/post/name-of-the-post"; thing, instead of 
"http://myhost/blog/view.php?id=id-of-the-post"; ?

I´ve seen this in many blogs, but it´s easy to implement?
See it in action at wikipedia, blogger blogs, simplebits 
<http://www.simplebits.com>.


Both simplebits and wikipedia is written in PHP, I guess.

Help!

Thank you



--

_____
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Simple logic but can't get it right

2006-11-09 Thread Myron Turner

You are testing unset variables.  This will work as you expect:

"; //Output is "b"...WHY?? It should be "outside"...

?>


Choy, Wai Yew wrote:

Hi gurus,

 


I've the following piece of PHP codeIt is a simple logic but I can't
get it rightThe output result of $id is "b"!!...It should be
"outside", right??

 


I think it is the variable $bCoz' it depend on the previous check (
if ($a == 0) ) for the value... If this is the case, how can I get this
logic works??

 


Thanks a million,

Choy

 

 

 

 


 


$a = 1;

$id = "outside";




if ($a == 0) {

  


$b = 1;

$id = "a";

  


}

 

 


elseif ($b == 0) {

  


$c = 1;

$id = "b";

  


}

 

 


elseif ($c == 0){

  


$d = 1;

$id = "c";

  


}

 




 echo "ID = $id"; //Output is "b"...WHY?? It should be "outside"...

 

 

 


?>





--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] CSS / PHP / Javascript

2006-11-16 Thread Myron Turner
You can use a browser sniffer, where they've done all the work for you, 
and then link in the appropriate stylesheet using document.write().  I 
don't have personal experience with the IE conditionals, but I would be 
concerned that they'd get you into a bit of a box when it comes to 
recognizing other browsers.


See:  http://www.webreference.com/tools/browser/javascript.html

Jochem Maas wrote:

hmmm, this reply turned into something that resembles a rant about halfway 
thru...
still ... maybe it's helpful in some way.

Ed Lazor wrote:

I'm reading a book on CSS and how you can define different style sheets
for different visitors.  I'm wondering how you guys do it.  The book
recommends using Javascript functions for identifying the user's browser
and matching them with the corresponding style sheets.  Anyone using PHP
for this instead - specifically with defining style sheets for different
target browsers and platforms?


having to define CSS files for particular browsers and/or platforms is 
indicative
of the crap we have to deal with - in theory you should NOT be targeting 
browser/platform
specificallt AT ALL. you should be writing stylesheets for different types
of user-agents (as defined by the W3C media types) - but who is really doing 
that.

I recommend trying to build your sites using CSS that all browsers understand
- i.e. avoid software/platform/version specific hacks whenever possible - when 
you
have to add such a hack try to use a technique that you can unobtrusively 
incorporate
into an existing CSS file.

the man named tantek has lots of techniques you can abuses ;-) :

e.g. http://tantek.com/CSS/Examples/midpass.html

also consider that maybe you shouldn't try and tackle every visual discrepency
between 2 different browsers/platforms! - you may have clients who bully you
into 'fixing' layout in WeirdBrowser1.4 for instance - you need to develop a
means to explain the problem to clients in such a way that they understand that
not everything is under your control, and that they can't make you endlessly
chase moving targets (i.e. make the client understand that web != print).

if a client is willing to pay for every mindnumbing hour spent fixing arcane
browser specific display 'bugs' then everything is okay - but don't get stuck
working for weeks for no pay because some marketing manager has 'decided' he/she
knows better what a website is and to what extent you must comply to his 
implicit
wishes [i.e. you can break every 'rule' of website building and ignore/rape 
any/every
relevant specification/standard so long as everything ispixel perfect in every 
browser according
to the original mockup supplied by a graphic designer who can't even grasp the 
concept
of screen resolution (I know plenty of print-based designers that fall into 
this category)]


-Ed

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




--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Space in regex

2006-11-16 Thread Myron Turner
The underscore plus alphanumeric are included in \w, so to get a regex 
such as you want:

[\w\s\.\-&\']+
You should escape the dot because the unescaped dot stands for any 
single character, which is why .* stands for any and all characters.


Dotan Cohen wrote:

I'm trying to match alphanumeric characters, some common symbols, and
spaces. Why does this NOT match strings containing spaces?:
[A-Za-z0-9\'.&-:underscore::space:]

I've also tried these, that also fail to match strings containing spaces:
[A-Za-z0-9\'.&- :underscore:]
[A-Z a-z0-9\'.&-:underscore:]
[:space:A-Za-z0-9\'.&-:underscore:]

All these regexes match strings containing the specified characters,
but none of them match strings with spaces.

Dotan Cohen

http://what-is-what.com/
http://technology-sleuth.com/



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Space in regex

2006-11-16 Thread Myron Turner
The \w regex includes all alphanumeric characters plus the underscore,
i.e. all valid characters that make up a C  identifier.  So what you
want can be expressed as follows:
[\w\s\.\-&]+
You have to escape the dot because in a regular espression it
represents any single character, which is why .* represents all
characters.


Myron Turner
http://www.mturner.org/XML_PullParser/


On Thu, 16 Nov 2006 23:08:34 +0200, [EMAIL PROTECTED] ("Dotan
Cohen") wrote:

>I'm trying to match alphanumeric characters, some common symbols, and
>spaces. Why does this NOT match strings containing spaces?:
>[A-Za-z0-9\'.&-:underscore::space:]
>
>I've also tried these, that also fail to match strings containing spaces:
>[A-Za-z0-9\'.&- :underscore:]
>[A-Z a-z0-9\'.&-:underscore:]
>[:space:A-Za-z0-9\'.&-:underscore:]
>
>All these regexes match strings containing the specified characters,
>but none of them match strings with spaces.
>
>Dotan Cohen
>
>http://what-is-what.com/
>http://technology-sleuth.com/

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



[PHP] Re: XML parser error ..

2006-11-22 Thread Myron Turner

Delete the initial extra line in:

> $xml_data = <<
> 

The XML Parser expects the XML document to start with a valid XML 
statement, which in your file is:  but yours starts 
with an newline.


 $xml_data = <<

onewaylife wrote:
Hi all 


I am novice in XML. I have just started to creating PHP parser for XML
files. I am using SAX. 
the file is : -
 

 

 

 

 








// cdata handler 

function characterDataHandler($parser, $data) 


{

  echo $data . ""; 

} 




// PI handler 

function PIHandler($parser, $target, $data) 


{

  // if php code, execute it 

  if (strtolower($target) == "php") 


  {

   eval($data); 

  } 

  // otherwise just print it 

  else 


  {

echo "PI found: [$target] $data"; 

  } 

} 




// XML data 

$xml_data = <<
 

 

  insert slug here 

  insert body here 


  ?>   

 

EOF; 




// initialize parser 

$xml_parser = xml_parser_create(); 




// set cdata handler 

xml_set_character_data_handler($xml_parser, "characterDataHandler"); 




// set PI handler 

xml_set_processing_instruction_handler($xml_parser, "PIHandler"); 




if (!xml_parse($xml_parser, $xml_data)) 


{

  die("XML parser error: " . 

xml_error_string(xml_get_error_code($xml_parser))); 

} 




// all done, clean up! 

xml_parser_free($xml_parser); 




?> 

 

 

it give this output " XML parser error: Reserved XML Name" 
even i created two more php files but it give same message as out put. 
I am unable to understand why its come. 


Please help me out.
onewaylife



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: PHP and XML

2006-11-24 Thread Myron Turner
I'm not sure you are going about this the right way.  It's my impression 
that you may not yet have learned the basics of XML.  Really, the very 
basics are quite simple.  For your address book, for instance, you could 
create a simple XML structure such as this:















Then write a script which fills in the data.

1. Start out with the document root:
echo "";
2. Fill in the data:
echo "$first_name";
echo "$last_name";
   And so forth.

3. Finish off with the document root:
echo "";

You can include the XML header once at the top of your file:



You don't need a special class or set of third-party functions to do a 
simple task like this.  You can easily write your own, and it will parse 
with any XML parser.



Myron

onewaylife wrote:


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








--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



[PHP] Re: Counting the occurences of items in an array

2006-12-24 Thread Myron Turner

From the manual:

array array_count_values ( array input)

array_count_values() returns an array using the values of the input 
array as keys and their frequency in input as values.


Example 1. array_count_values() example


The printout of the above program will be:

Array
(
[1] => 2
[hello] => 2
[world] => 1
)

Dotan Cohen wrote:

Has this wheel been invented, but simpler? I've an array of words that
I'd like to know how many occurences of each there are. For instance:
$fruits = array(
   "lemon",
   "orange",
   "banana",
   "apple",
   "orange",
   "banana",
   "orange");

And I'd like to create this:
$fruit_count = array(
   "lemon" => 1,
   "orange" => 3,
   "banana" => 2,
   "apple" => 1);

My current plan of action is to create $fruit_count, and check if
$fruits[0] is listed in it. If not, then I'll add it with a value of
1. If it is already listed then I'll just increase it's number. Ditto
for $fruits[1] and so on...

Has someone cleverer than myself found a better way of doing this?
This function will be used as a word count for text documents, and
some of them have over 5000 words. So if there's a better way of doing
this I'd love to know. Thanks.

Dotan Cohen

http://what-is-what.com/what_is/html_email.html
http://lyricslist.com/lyrics/artist_albums/162/disturbed.php



--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



  1   2   >