php-general Digest 19 Jun 2005 11:08:19 -0000 Issue 3520

Topics (messages 217172 through 217190):

SFTP problems
        217172 by: Lowell Allen

Re: comparing two texts
        217173 by: Jochem Maas
        217174 by: jenny mathew
        217182 by: Richard Lynch
        217184 by: Richard Lynch
        217189 by: Edward Vermillion
        217190 by: jenny mathew

SFTP problem
        217175 by: Lowell Allen

asterix for arrray_search?
        217176 by: Merlin
        217177 by: Yasir Malik
        217181 by: Richard Lynch

Merging Duplicate array items
        217178 by: Joe Harman

Re: rename
        217179 by: Mister Jack
        217183 by: Richard Lynch

Re: [SOLVED] Merging Duplicate array items
        217180 by: Joe Harman

Re: possible jscript/php/frames question!!
        217185 by: Richard Lynch

Re: sorting object props
        217186 by: Richard Lynch

Re: passthru() passing variables
        217187 by: Richard Lynch

Re: Using Exec Function
        217188 by: Richard Lynch

Administrivia:

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

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

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message --- I need to use SFTP to send text files and binary files from one server to another, but I'm unable to use fopen on the remote server, and if I send with ssh2_scp_send the files are truncated. I'm assuming the libssh2-PECL/ssh2 installation isn't the problem because I'm able to connect using ssh2_auth_password, create a directory on the remote server with ssh2_sftp_mkdir, and copy files with ssh2_sftp_send and ssh2_sftp_recv (even though ssh2_sftp_send truncates files).

When I try to use fopen, I get this error message:

Warning: fopen(): Unable to open ssh2.sftp://Resource id #10/whatever.com:22/home/whatever/public_html/flamingo/test.txt on remote host in /home/user/public_html/cms/sftp_test.php on line 79

Warning: fopen(ssh2.sftp://Resource id #10/whatever.com:22/home/whatever/public_html/flamingo/test.txt): failed to open stream: Resource temporarily unavailable in /home/user/public_html/cms/sftp_test.php on line 79

Here's line 79 of sftp_test.php:

$stream = fopen("ssh2.sftp://$sftp/whatever.com:22/home/whatever/public_html/ flamingo/".$filename, "wt")

I've read "Secure Communications with PHP and SSH" in the February PHP Architect. That's what prompted me to try PECL/ssh2, but now I'm stuck. Anybody successfully using fopen with SFTP or anybody using ssh2_sftp_send without getting truncated files?

--
Lowell Allen

--- End Message ---
--- Begin Message ---
jenny mathew wrote:
hello group,
is it possible to compare two different text messages and highlight
the difference in php.
i mean to say that $text1="message 1"
$text2="message 2"
i want to compare both $text1 and $text2 for differences and highlight
the differece in php.is it possible.

yes. is it easy? that depends on how far you want to go with diff'ing
(and how good you are at string manipulation :-)

this is a general problem which has been solved by very skilled people
already, I would suggest reading some more about 'diff' etc and
figure out if you can use existing tools to get what you want:

http://www.gnu.org/software/diffutils/diffutils.html
http://en.wikipedia.org/wiki/Diff

waiting for your reply.
thanks.
Yours,
Jenny


--- End Message ---
--- Begin Message ---
i want to compare two text fetched out of database and echo the result
on the webpage.i want to do it in php language and i donot want to
compare two text files ,i wanna compare two text messages (that is
fetched out from database).
thanks.
Yours,
Jenny.

On 6/18/05, Jochem Maas <[EMAIL PROTECTED]> wrote:
> jenny mathew wrote:
> > hello group,
> > is it possible to compare two different text messages and highlight
> > the difference in php.
> > i mean to say that
> > $text1="message 1"
> > $text2="message 2"
> > i want to compare both $text1 and $text2 for differences and highlight
> > the differece in php.is it possible.
> 
> yes. is it easy? that depends on how far you want to go with diff'ing
> (and how good you are at string manipulation :-)
> 
> this is a general problem which has been solved by very skilled people
> already, I would suggest reading some more about 'diff' etc and
> figure out if you can use existing tools to get what you want:
> 
> http://www.gnu.org/software/diffutils/diffutils.html
> http://en.wikipedia.org/wiki/Diff
> 
> > waiting for your reply.
> > thanks.
> > Yours,
> > Jenny
> >
> 
>

--- End Message ---
--- Begin Message ---
On Sat, June 18, 2005 9:41 am, jenny mathew said:
> i want to compare two text fetched out of database and echo the result
> on the webpage.i want to do it in php language and i donot want to
> compare two text files ,i wanna compare two text messages (that is
> fetched out from database).

I believe you will find it more feasible to throw your two messages into
files and use exec() to call diff on them than to write essentially all of
"diff" in PHP...

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Sat, June 18, 2005 3:21 am, jenny mathew said:
> is it possible to compare two different text messages and highlight
> the difference in php.
> i mean to say that
> $text1="message 1"
> $text2="message 2"
> i want to compare both $text1 and $text2 for differences and highlight
> the differece in php.is it possible.
> waiting for your reply.

Untested, very crude:

<?php
  $maxlen = max(strlen($text1), strlen($text2));
  for ($i = 0; $i < $maxlen; $i++){
    if (@$text1[$i] == @$text2[$i]) echo @$text1[$i];
    else @echo "<font color=red>$text1[$i]|$text2[$i]</font>";
  }
?>

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---

On Jun 18, 2005, at 3:42 PM, Richard Lynch wrote:

On Sat, June 18, 2005 3:21 am, jenny mathew said:
is it possible to compare two different text messages and highlight
the difference in php.
i mean to say that
$text1="message 1"
$text2="message 2"
i want to compare both $text1 and $text2 for differences and highlight
the differece in php.is it possible.
waiting for your reply.

Untested, very crude:

<?php
  $maxlen = max(strlen($text1), strlen($text2));
  for ($i = 0; $i < $maxlen; $i++){
    if (@$text1[$i] == @$text2[$i]) echo @$text1[$i];
    else @echo "<font color=red>$text1[$i]|$text2[$i]</font>";
  }
?>

--
Like Music?
http://l-i-e.com/artists.htm

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



Would it be possible to explode both messages on " " into an array and run array_diff() and work from there?
Just a thought late in the day...

Edward Vermillion
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
> Untested, very crude:
> 
> <?php
> $maxlen = max(strlen($text1), strlen($text2));
> for ($i = 0; $i < $maxlen; $i++){
> if (@$text1[$i] == @$text2[$i]) echo @$text1[$i];
> else @echo "<font color=red>$text1[$i]|$text2[$i]</font>";
> }
> ?>
 donot you think you program will just bring the server to its foot ,if the 
text message encountered is very large of order of 40 KB or
larger.is<http://larger.is>there any other efficient method.

--- End Message ---
--- Begin Message --- I need to use SFTP to send text files and binary files from one server to another, but I'm unable to use fopen on the remote server, and if I send with ssh2_scp_send the files are truncated. I'm assuming the libssh2-PECL/ssh2 installation isn't the problem because I'm able to connect using ssh2_auth_password, create a directory on the remote server with ssh2_sftp_mkdir, and copy files with ssh2_sftp_send and ssh2_sftp_recv (even though ssh2_sftp_send truncates files).

When I try to use fopen, I get this error message:

Warning: fopen(): Unable to open ssh2.sftp://Resource id #10/whatever.com:22/home/whatever/public_html/flamingo/test.txt on remote host in /home/user/public_html/cms/sftp_test.php on line 79

Warning: fopen(ssh2.sftp://Resource id #10/whatever.com:22/home/whatever/public_html/flamingo/test.txt): failed to open stream: Resource temporarily unavailable in /home/user/public_html/cms/sftp_test.php on line 79

Here's line 79 of sftp_test.php:

$stream = fopen("ssh2.sftp://$sftp/whatever.com:22/home/whatever/public_html/ flamingo/".$filename, "wt")

I've read "Secure Communications with PHP and SSH" in the February PHP Architect. That's what prompted me to try PECL/ssh2, but now I'm stuck. Anybody successfully using fopen with SFTP or anybody using ssh2_sftp_send without getting truncated files?

--
Lowell Allen

--- End Message ---
--- Begin Message ---
Hi there,

I am trying to find out how to match a search on : 5a or 5b with array search.
Basicly I would like to make it true as soon as the function finds a value starting with 5.

As for now I have:
if (array_search('5a', $emsg) OR array_search('5b', $emsg)){
...

that statement will get very long till z :-)

Any ideas how to make something like this:
array_search('5*', $emsg)

Thank you for any hint,

Merlin

--- End Message ---
--- Begin Message ---
As for now I have:
if (array_search('5a', $emsg) OR array_search('5b', $emsg)){
...

that statement will get very long till z :-)

Any ideas how to make something like this:
array_search('5*', $emsg)

How about something like:
search($emsg)
{
  for($i = 0; $i < count($emsg); $i++)
    if(preg_match('/5[a-z]/', $emsg[$i]))
      return $i;

  return -1;
}

Regards,
Yasir

--- End Message ---
--- Begin Message ---
On Sat, June 18, 2005 10:11 am, Merlin said:
> I am trying to find out how to match a search on : 5a or 5b with array
> search.
> Basicly I would like to make it true as soon as the function finds a value
> starting with 5.
>
> As for now I have:
> if (array_search('5a', $emsg) OR array_search('5b', $emsg)){
> ...
>
> that statement will get very long till z :-)
>
> Any ideas how to make something like this:
> array_search('5*', $emsg)

I believe that in recent versions of PHP, the preg_* functions will accept
an array as an argument... Or maybe I dreamed that.

You should benchmark the solutions and also consider just using implode()
on the array to make a giant string and search that.

Depending on a lot of factors, any of these could out-perform the others.

Try it with data as close to real-world as you can get.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
Hello, I've been trying to figure out on how I could evaluated this
array and combine like items... here is the array.. it represents a
shopping cart contents.. you'll notice that the first array is the
same as the third... what I am trying to do is combine the quantity of
the first array and the third... I am not asking from someone to
program this for me... just for someone to give me a heads up on if
there is a array function I could use. Thanks for any help!

------------- array example --------------------

$ARY_cart[] = array(    'product_id' => '123',
                                                                'sku' => 
'DFBag-12',
                                                                'quantity' => 
'2',
                                                                'product_name' 
=> 'Dog Food',
                                                                'unit' => '12 
lbs. Bag',
                                                                'price' => 
'12.05'
                                                                );
$ARY_cart[] = array(    'product_id' => '224',
                                                                'sku' => 
'cFBag-6',
                                                                'quantity' => 
'1',
                                                                'product_name' 
=> 'Cat Food',
                                                                'unit' => '8 
lbs. Bag',
                                                                'price' => 
'4.25'
                                                                );
$ARY_cart[] = array(    'product_id' => '123',
                                                                'sku' => 
'DFBag-12',
                                                                'quantity' => 
'24',
                                                                'product_name' 
=> 'Dog Food',
                                                                'unit' => '12 
lbs. Bag',
                                                                'price' => 
'12.05'
                                                                );


-- 
Joe Harman
---------
Do not go where the path may lead, go instead where there is no path
and leave a trail. - Ralph Waldo Emerson

--- End Message ---
--- Begin Message ---
Hi,

That's what I've done, but I does not say clearly _when_ @rename
should failed. I've read the documentation in the C library for Unix,
and it says that it failed when it can't _add_ an entry to the
directory. What I observe is an empty file...
still weird, I'll look depper into it. (since i've been bitten by it
with my website being 'blank page' since it grew out of space...)
Thanks,

On 6/18/05, Bob Winter <[EMAIL PROTECTED]> wrote:
> Look at http://us2.php.net/manual/en/function.rename.php
> 
> Mister Jack wrote:
> > Hi,
> >
> > I would like to know precisely what rename do in case of error. any
> > link for that ?
> > I do a : @rename($old, $new), what happens if I run out of space ? is
> > the rename just an alias for C function library ?
> > thanks
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

--- End Message ---
--- Begin Message ---
On Sat, June 18, 2005 3:50 am, Mister Jack said:
> I would like to know precisely what rename do in case of error. any
> link for that ?

It will probably return 0 (or maybe -1) on error.

It may or may not also fill in $php_errmessage (?) or whatever the
variable is called.

It should be documented at http://php.net/rename what error codes it returns.

If not, you could run some tests fairly easily.

> I do a : @rename($old, $new), what happens if I run out of space ?

It won't work, and you have suppressed the error message, so you won't
even know it didn't work.

Using @ like that is just a Bad Idea.

You need to write better software that handles error conditions and does
something reasonable about them.

? is
> the rename just an alias for C function library ?

Pretty much, but not to the point that it blindly returns whatever the C
'rename' returns, probably.

You could read the PHP source and find out :-)
http://cvs.php.net

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
I think I solved the issue i was having... I would be willing for any
optimization though.. .here is what I did
------------------------- code -------------

$ARY_cart[] = array(    'product_id' => '123',
                'sku' => 'DFBag-12',
                'quantity' => '2',
                'product_name' => 'Dog Food',
                'unit' => '12 lbs. Bag',
                'price' => '12.05'
                );
$ARY_cart[] = array(    'product_id' => '224',
                'sku' => 'cFBag-6',
                'quantity' => '1',
                'product_name' => 'Cat Food',
                'unit' => '8 lbs. Bag',
                'price' => '4.25'
                );
$ARY_cart[] = array(    'product_id' => '123',
                'sku' => 'DFBag-12',
                'quantity' => '24',
                'product_name' => 'Dog Food',
                'unit' => '12 lbs. Bag',
                'price' => '12.05'
                );
                                                
$cart_count = 0;
$cart_total = count($ARY_cart);
foreach ($ARY_cart as $key => $ary_value)
        {               
        do{
                if($ary_value['product_id'] == 
$ARY_cart[$cart_count]['product_id']
&& $key <> $cart_count)
                {
                $ARY_cart[$cart_count]['quantity'] =
$ARY_cart[$cart_count]['quantity'] + $ARY_cart[$key]['quantity'];
                unset($ARY_cart[$key]);
                }
                $cart_count++;
                } while ($cart_count == $cart_total);
                
                $cart_count = 0;
        }                               


On 6/18/05, Joe Harman <[EMAIL PROTECTED]> wrote:
> Hello, I've been trying to figure out on how I could evaluated this
> array and combine like items... here is the array.. it represents a
> shopping cart contents.. you'll notice that the first array is the
> same as the third... what I am trying to do is combine the quantity of
> the first array and the third... I am not asking from someone to
> program this for me... just for someone to give me a heads up on if
> there is a array function I could use. Thanks for any help!
> 
> ------------- array example --------------------
> 
> $ARY_cart[] = array(    'product_id' => '123',
>                                                                'sku' => 
> 'DFBag-12',
>                                                                'quantity' => 
> '2',
>                                                                'product_name' 
> => 'Dog Food',
>                                                                'unit' => '12 
> lbs. Bag',
>                                                                'price' => 
> '12.05'
>                                                                );
> $ARY_cart[] = array(    'product_id' => '224',
>                                                                'sku' => 
> 'cFBag-6',
>                                                                'quantity' => 
> '1',
>                                                                'product_name' 
> => 'Cat Food',
>                                                                'unit' => '8 
> lbs. Bag',
>                                                                'price' => 
> '4.25'
>                                                                );
> $ARY_cart[] = array(    'product_id' => '123',
>                                                                'sku' => 
> 'DFBag-12',
>                                                                'quantity' => 
> '24',
>                                                                'product_name' 
> => 'Dog Food',
>                                                                'unit' => '12 
> lbs. Bag',
>                                                                'price' => 
> '12.05'
>                                                                );
> 
> 
> --
> Joe Harman
> ---------
> Do not go where the path may lead, go instead where there is no path
> and leave a trail. - Ralph Waldo Emerson
> 


-- 
Joe Harman
---------
Do not go where the path may lead, go instead where there is no path
and leave a trail. - Ralph Waldo Emerson

--- End Message ---
--- Begin Message ---
On Fri, June 17, 2005 3:47 pm, bruce said:
> i've got a problem where i'm trying to play with imagemaps. i created a
> test
> image map, but when i select inside the image map, i 'see' the "?x,y" from
> the imagemap, appended to the url in the browser address bar... i get
> http://foo.com?3,5 etc...
>
> is there a way to prevent this from occuring??

Sure.

Change your LINK to a FORM with an INPUT TYPE="image" and use
METHOD="POST" on the FORM tag.

<form method="post"><input type="image" name="clicked"
src="images/clicker.jpg"></form>
<?php
  if (isset($clicked_x)){
    echo "($clicked_x, $clicked_y)<br />";
  }
?>

I dunno why everybody else gave you such complicated answers.

It's still not a PHP question, though, except it's confusing PHP changes
".x" and ".y" into "_x" and "_y" on the variable names because "." is not
valid in variable names. :-)

There, that made this post on-topic.  Sort of.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, June 17, 2005 2:48 pm, D_C said:
> is there a way to sort the properties of an object by their name, much
> like sort works on arrays?
>
> i am getting back an object from a database query and want to list the
> resulting items in alpha order by field name...

http://php.net/ksort

Last time I checked, PHP would still convert an object to an array if you
forced it to...

If not, there are introspective functions to examine your object and all
its properties, and surely you could build the array yourself and then
ksort it.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, June 17, 2005 6:47 am, Jason Barnett said:
> What is a reliable cross-platform way of showing which user PHP is
> running as?

http://php.net/get_current_user

The bogus User Contributed note about REMOTE_USER is, well, bogus, almost
for sure.

If that fails, I guess you could try:

<?php
  ob_start();
  phpinfo();
  $phpinfo = ob_endclean();
?>

Then you have to dig out the PHP User from that.

It's possible there is a PHP Constant here that is the User:
http://php.net/manual/en/language.constants.predefined.php

If none of those work, I'm guessing even Windoze has something like
"whoami" so you could http://php.net/exec "whoami" or its equivalent,
based on the http://php.net/php_sapi_name

If all that fails, I'd just give up. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---
--- Begin Message ---
On Fri, June 17, 2005 5:50 am, Davide Pasqualini said:
> I did as You suggested:
>
> <?php
> $win_cmd = "\"C:\\Hello.exe\"";
> exec($win_cmd, $stdout, $stderr);
> print "Standard output:\n";
> print_r($stdout);
> print "Standard error:\n";
> print_r($stderr);
> ?>
>
> but Hello.Exe, a very simple program, doesn't run and my browser seems
> waiting something from the server.
>
> Can I run a program (exe file) in another way ?

If you've got the Hello.exe running, but not returning, you could *MAYBE*
do :

<?php exec("Hello.exe &", $output, $error);?>

The & will put it into the background, even in Windoze, I think...  If
not, figure out how Windows starts background tasks, and do that.

Or make Hello.exe actually be a tiny little program that forks off the
program you really want to use, and then returns.

Or...  Lots of ways to try to force the OS to fork the process.

-- 
Like Music?
http://l-i-e.com/artists.htm

--- End Message ---

Reply via email to