php-general Digest 12 May 2008 07:02:40 -0000 Issue 5454

Topics (messages 274155 through 274171):

creating an xls file from mysql data
        274155 by: Richard Kurth
        274156 by: Andrew Johnstone

Re: How to determine if file is writable and deletable
        274157 by: Al
        274161 by: Robert Cummings
        274163 by: Shawn McKenzie
        274164 by: Shawn McKenzie

Re: Help with a foreach statement
        274158 by: Craige Leeder

Re: unsubscribe
        274159 by: Craige Leeder

Re: $_SESSION v. Cookies
        274160 by: Craige Leeder

Re: Division [maybe a bug]
        274162 by: Chris W

mysql_pconnect issue
        274165 by: bruce
        274168 by: Chris
        274169 by: Forcey

Ignore Tags
        274166 by: Jorge Peña
        274167 by: Jorge Peña
        274170 by: Adam Richardson

Good XML Parser
        274171 by: Waynn Lue

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 ---

This script will create an xls file from the data that is sent to it
When I run this it only gets one recored and it is supposet to get all the records that are past by the $_POST[selectedcontactlist] I think I have a } in the wrong place but I can not figure it out anybody have a suggestion

$_POST[selectedcontactlist]="3,45,65,23,12,4,56"; //this is a sample of what is past

$ExplodeIt = explode(",",rtrim($_POST[selectedcontactlist],","));
$Count = count($ExplodeIt);
for ($i=0; $i < $Count; $i++) {
$sql = "SELECT * FROM contacts WHERE id = '$ExplodeIt[$i]'";
$sql_result = query($sql);
$count = mysql_num_fields($sql_result);

for ($i = 0; $i < $count; $i++){
   $header .= mysql_field_name($sql_result, $i)."\t";
}

while($row = mysql_fetch_row($sql_result)){
 $line = '';
 foreach($row as $value){
   if(!isset($value) || $value == ""){
     $value = "\t";
   }else{
# important to escape any quotes to preserve them in the data.
     $value = str_replace('"', '""', $value);
# needed to encapsulate data in quotes because some data might be multi line.
# the good news is that numbers remain numbers in Excel even though quoted.
     $value = '"' . $value . '"' . "\t";
   }
   $line .= $value;
 }
 $data .= trim($line)."\n";
}
}
# this line is needed because returns embedded in the data have "\r"
# and this looks like a "box character" in Excel
 $data = str_replace("\r", "", $data);


# Nice to let someone know that the search came up empty.
# Otherwise only the column name headers will be output to Excel.
if ($data == "") {
 $data = "\nno matching records found\n";
}

# This line will stream the file to the user rather than spray it across the screen
header("Content-type: application/octet-stream");

# replace excelfile.xls with whatever you want the filename to default to
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo $header."\n".$data;


--- End Message ---
--- Begin Message ---
Hi,
You could always do this within mysql itself. You also have the wrong output
header and what seems to be some quite inefficient code, anyway take a look
at the following.

SELECT order_id,product_name,qty
    FROM orders
    INTO OUTFILE '/tmp/orders.csv'
        FIELDS TERMINATED BY ','
        ENCLOSED BY '"'
        LINES TERMINATED BY '\n'

Thanks

Andrew

2008/5/11 Richard Kurth <[EMAIL PROTECTED]>:

>
> This script will create an xls file from the data that is sent to it
> When I run this it only gets one recored and it is supposet to get all the
> records that are past by the  $_POST[selectedcontactlist]
> I think I have a } in the wrong place but I can not figure it out anybody
> have a suggestion
>
> $_POST[selectedcontactlist]="3,45,65,23,12,4,56"; //this is a sample of
> what is past
>
> $ExplodeIt = explode(",",rtrim($_POST[selectedcontactlist],","));
> $Count = count($ExplodeIt);
> for ($i=0; $i < $Count; $i++) {
> $sql = "SELECT * FROM contacts WHERE id = '$ExplodeIt[$i]'";
> $sql_result = query($sql);
> $count = mysql_num_fields($sql_result);
>
> for ($i = 0; $i < $count; $i++){
>   $header .= mysql_field_name($sql_result, $i)."\t";
> }
>
> while($row = mysql_fetch_row($sql_result)){
>  $line = '';
>  foreach($row as $value){
>   if(!isset($value) || $value == ""){
>     $value = "\t";
>   }else{
> # important to escape any quotes to preserve them in the data.
>     $value = str_replace('"', '""', $value);
> # needed to encapsulate data in quotes because some data might be multi
> line.
> # the good news is that numbers remain numbers in Excel even though quoted.
>     $value = '"' . $value . '"' . "\t";
>   }
>   $line .= $value;
>  }
>  $data .= trim($line)."\n";
> }
> }
> # this line is needed because returns embedded in the data have "\r"
> # and this looks like a "box character" in Excel
>  $data = str_replace("\r", "", $data);
>
>
> # Nice to let someone know that the search came up empty.
> # Otherwise only the column name headers will be output to Excel.
> if ($data == "") {
>  $data = "\nno matching records found\n";
> }
>
> # This line will stream the file to the user rather than spray it across
> the screen
> header("Content-type: application/octet-stream");
>
> # replace excelfile.xls with whatever you want the filename to default to
> header("Content-Disposition: attachment; filename=excelfile.xls");
> header("Pragma: no-cache");
> header("Expires: 0");
>
> echo $header."\n".$data;
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message --- I ended up using posix_access() which is what is_writeable() should be. is_writeable() is virtually useless.

Al wrote:
I need to determine if a file is truly deletable by a php script, Deleting permissions seem to be the same as writing, they probably have the same criteria.

is_writable() seems to virtually useless in most cases. It doesn't take into account the directory ownership/permissions; which, best I can tell, is the real determining factor.

I've resorted to having to determine the directory's ownership and then compare the directory's rights with the owner's and then the other ['world'].

E.g., Assume my script was loaded with ftp, so it's ownership is the site-name, and I want the scrip to be able to determine if it can delete a file. Thus, the file in question must have its "other" permissions include write.

Surely, there must be an easier way.

Thanks, Al........

--- End Message ---
--- Begin Message ---
On Sun, 2008-05-11 at 18:09 -0400, Al wrote:
> I ended up using posix_access() which is what is_writeable() should be.  
> is_writeable() is virtually 
> useless.

So you're saying is_writeable() shouldn't work on Windows systems? :p
Seems you want is_writeable() to sing AND dance... perhaps too much
expecting.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


--- End Message ---
--- Begin Message ---
Al wrote:
I ended up using posix_access() which is what is_writeable() should be. is_writeable() is virtually useless.

Al wrote:
I need to determine if a file is truly deletable by a php script, Deleting permissions seem to be the same as writing, they probably have the same criteria.

is_writable() seems to virtually useless in most cases. It doesn't take into account the directory ownership/permissions; which, best I can tell, is the real determining factor.

I've resorted to having to determine the directory's ownership and then compare the directory's rights with the owner's and then the other ['world'].

E.g., Assume my script was loaded with ftp, so it's ownership is the site-name, and I want the scrip to be able to determine if it can delete a file. Thus, the file in question must have its "other" permissions include write.

Surely, there must be an easier way.

Thanks, Al........
Not if you read Robin's post.

-Shawn

--- End Message ---
--- Begin Message ---
Al wrote:
I ended up using posix_access() which is what is_writeable() should be. is_writeable() is virtually useless.

Al wrote:
I need to determine if a file is truly deletable by a php script, Deleting permissions seem to be the same as writing, they probably have the same criteria.

is_writable() seems to virtually useless in most cases. It doesn't take into account the directory ownership/permissions; which, best I can tell, is the real determining factor.

I've resorted to having to determine the directory's ownership and then compare the directory's rights with the owner's and then the other ['world'].

E.g., Assume my script was loaded with ftp, so it's ownership is the site-name, and I want the scrip to be able to determine if it can delete a file. Thus, the file in question must have its "other" permissions include write.

Surely, there must be an easier way.

Thanks, Al........
Not if you read Robin's post.

-Shawn

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

This code should work:

<?php

$path_to_shopping_cart = './';
$iLength = count($cart);

foreach ($cart as $product_name => $quantity)
{
  echo "<li><a href=\"" . $path_to_shopping_cart . "product/" .
          $cart[$product_id] . "/\">" . $product_name . "</a> - " . $quantity .
            "</li>\r\n";
}

?>

Though I'm not sure about $cart[$product_id]. Where is that coming
from?. It makes no sense here. Perhaps you want to do a
tri-demensional array in $_session, so you will have a
dual-demesnional array in $cart.

Let me know,
- Craige

On Sun, May 11, 2008 at 2:54 PM, Ron Piggott <[EMAIL PROTECTED]> wrote:
> I am writing a shopping cart.
>
> Products assigned in the following fashion:
> $_SESSION['selection'][$product]=$quantity;
>
> I am wanting to display the list of products in the shopping cart in a
> list for the user to see as they continue shopping.
>
> I put the SESSION variable into $cart
>
> $cart = $_SESSION['selection'];
>
> then I start the foreach and this is where I get messed up.  I am trying
> to ECHO the following syntax to the screen with each selected product:
>
> The part I need help with is to write the foreach loop to give me
> $product (so I may query the database to find out the product name) and
> the $quantity (so I may show the user what they are purchasing).  The
> part that is messing me up is that this is an array.
>
> My ECHO statement should look like this:
>
> echo "<li><a href=\"" . $path_to_shopping_cart . "product/" .
> $cart[$product_id] . "/\">" . $product_name . "</a> - " . $quantity .
> "</li>\r\n";
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
> You've even had to resort to using classes and other strange stuff to
> program. Clearly signs of mental fatigue. :-)

:o. I think mental fatigue might be evident by one not using it. But
that's just me ;)

- Craige

--- End Message ---
--- Begin Message ---
I can't see PHP sessions slowing down your site by that amount. As
someone said, it should be no more than a split second. If you are
having that much of a problem with them, then I would say it is either
your implementation, or another determining factor.

I would not, personally, stray away from PHP's GC of sessions. I would
imagine that any third-party concoction could not be any faster. I
would however, check to see how long PHP takes to clean up defunct
sessions, and also monitor how many sessions are lying around at any
given time.

Regards,
- Craige

--- End Message ---
--- Begin Message ---
jo opp wrote:
2008/5/11 Chris W <[EMAIL PROTECTED]>:
jo opp wrote:

Hello!

$var1= 2155243640%31104000;
$var2= 2147309244%31104000;

echo $var1 // Return -24651656
echo $var2 // Return 1133244

$var2 return the correct result, but $var1 is wrong (the correct
result is 9067640)

 Probably because the maximum signed 32 bit integer value is
 2,147,483,648


OK, but with bigger numbers works fine again.
Right now I made a function to deal with this issue:

function remainder($dividend,$divisor){
        $remainder= $dividend-(floor($dividend/$divisor)*$divisor);
        return $remainder;
}

What do you think about it?


That will convert the numbers to floating point, which will give you round off error if the numbers get too big.

--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm";

Ham Radio Repeater Database.
http://hrrdb.com

--- End Message ---
--- Begin Message ---
hi...

running into a problem that i can't seem to solve...

using mysql_pconnect() and i'm trying to figure out what parameters have to
be used in order to connect to a local mysql session, where mysql is
accessed using the defaults (ie, no user/passwd/hostIP)

i can connect via the cli, by doing >>mysql, which accesses the db app..

however, for the life of me, i can't figure out what attributes to use to
simply be able to access mysql from within a php app running on apache.

it appears that mysql_connect/pconnect requires an actual user/passwd/hostIP
in order to work.

using mysql_connect("","","") or mysql_connect('""','""','"") returns an
error..

i've looked in the php.ini file and set everything (user/passwd/host) to ""
with no louck..

any pointers would be helpful. (i can easily access the mysql if i set up a
user (grant access.....)

but for now, i'm curious as to how to access the default mysql setup...

thanks

peace


--- End Message ---
--- Begin Message ---
bruce wrote:
> hi...
> 
> running into a problem that i can't seem to solve...
> 
> using mysql_pconnect() and i'm trying to figure out what parameters have to
> be used in order to connect to a local mysql session, where mysql is
> accessed using the defaults (ie, no user/passwd/hostIP)

Use 'localhost' for the host, no idea what you'd use for the user/pass,
but mysql requires a username at least. If you're not entering one, it's
using the username you are logged in as.

-- 
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
On Mon, May 12, 2008 at 12:27 PM, Chris <[EMAIL PROTECTED]> wrote:
> bruce wrote:
>  > hi...
>  >
>  > running into a problem that i can't seem to solve...
>  >
>  > using mysql_pconnect() and i'm trying to figure out what parameters have to
>  > be used in order to connect to a local mysql session, where mysql is
>  > accessed using the defaults (ie, no user/passwd/hostIP)
>
>  Use 'localhost' for the host, no idea what you'd use for the user/pass,
>  but mysql requires a username at least. If you're not entering one, it's
>  using the username you are logged in as.
>
I guess the default user is 'root' and password is empty.

- forcey

>  --
>  Postgresql & php tutorials
>  http://www.designmagick.com/
>
>
>
>  --
>  PHP General Mailing List (http://www.php.net/)
>  To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hello. I am writing a script that scans some content for email addresses and
then encrypts them in a way to hide them from spam bots (For more
information, http://mailhide.recaptcha.net/ ). The Regular Expressions work
perfectly fine, I look for plain email addresses as well as hyperlink email
addresses (<a href="mailto:[EMAIL PROTECTED]"> and <a href="[EMAIL 
PROTECTED]">).
I am nearly done writing the script, the last requested feature is to have
some sort of tags or way of making it so that the emails within these tags
don't get encrypted. So for example the email within
[EMAIL PROTECTED]/nomailhide] won't get encrypted. I know how to
scan for the nomailhide tags and get its contents, I just can't figure out
how to make it so that the callbacks that encrypt the emails don't touch, or
ignore, the emails within the nomailhide tags. Perhaps I'm over complicating
things, but I've already asked people in regex and php IRC channels and they
too can't figure it out. I've spent 5 hours or so on this one problem and I
think my head's about to explode so I'm going to leave it for a while.

I would REALLY appreciate it if anyone could please help me out with this in
any way possible, I would really value your time. Please, someone, I'm so
desperate. If my message isn't really descriptive or anything please let me
know, it's just that I'm so sick and tired of all of this.

--- End Message ---
--- Begin Message ---
Just to show how exhausted I am: I forgot to provide a link to the relevant
source code. Here it is: http://paste.blaenkdenum.com/351

On Sun, May 11, 2008 at 9:25 PM, Jorge Peña <[EMAIL PROTECTED]> wrote:

> Hello. I am writing a script that scans some content for email addresses
> and then encrypts them in a way to hide them from spam bots (For more
> information, http://mailhide.recaptcha.net/ ). The Regular Expressions
> work perfectly fine, I look for plain email addresses as well as hyperlink
> email addresses (<a href="mailto:[EMAIL PROTECTED]"> and <a href="
> [EMAIL PROTECTED]">). I am nearly done writing the script, the last requested
> feature is to have some sort of tags or way of making it so that the emails
> within these tags don't get encrypted. So for example the email within
> [EMAIL PROTECTED]/nomailhide] won't get encrypted. I know how to
> scan for the nomailhide tags and get its contents, I just can't figure out
> how to make it so that the callbacks that encrypt the emails don't touch, or
> ignore, the emails within the nomailhide tags. Perhaps I'm over complicating
> things, but I've already asked people in regex and php IRC channels and they
> too can't figure it out. I've spent 5 hours or so on this one problem and I
> think my head's about to explode so I'm going to leave it for a while.
>
> I would REALLY appreciate it if anyone could please help me out with this
> in any way possible, I would really value your time. Please, someone, I'm so
> desperate. If my message isn't really descriptive or anything please let me
> know, it's just that I'm so sick and tired of all of this.
>

--- End Message ---
--- Begin Message ---
I didn't check out your source, but in terms of a regex that only matches
items not surrounded by some special tag, what about negative lookaheads and
lookbehinds, like:

(?<!\[specialtag\])REST_OF_YOUR_REGEX(?!\[specialtag\])

I've not used them in PHP, but just a quick thought that might help.

You can read more at the site below:
http://www.regular-expressions.info/lookaround.html

Adam

-----Original Message-----
From: Jorge Peña <[EMAIL PROTECTED]> [mailto:=?ISO-8859-1?Q?
Jorge_Pe=F1a _<[EMAIL PROTECTED]>?=] 
Sent: Monday, May 12, 2008 12:27 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Ignore Tags

Just to show how exhausted I am: I forgot to provide a link to the relevant
source code. Here it is: http://paste.blaenkdenum.com/351

On Sun, May 11, 2008 at 9:25 PM, Jorge Peña <[EMAIL PROTECTED]> wrote:

> Hello. I am writing a script that scans some content for email addresses
> and then encrypts them in a way to hide them from spam bots (For more
> information, http://mailhide.recaptcha.net/ ). The Regular Expressions
> work perfectly fine, I look for plain email addresses as well as hyperlink
> email addresses (<a href="mailto:[EMAIL PROTECTED]"> and <a href="
> [EMAIL PROTECTED]">). I am nearly done writing the script, the last requested
> feature is to have some sort of tags or way of making it so that the
emails
> within these tags don't get encrypted. So for example the email within
> [EMAIL PROTECTED]/nomailhide] won't get encrypted. I know how to
> scan for the nomailhide tags and get its contents, I just can't figure out
> how to make it so that the callbacks that encrypt the emails don't touch,
or
> ignore, the emails within the nomailhide tags. Perhaps I'm over
complicating
> things, but I've already asked people in regex and php IRC channels and
they
> too can't figure it out. I've spent 5 hours or so on this one problem and
I
> think my head's about to explode so I'm going to leave it for a while.
>
> I would REALLY appreciate it if anyone could please help me out with this
> in any way possible, I would really value your time. Please, someone, I'm
so
> desperate. If my message isn't really descriptive or anything please let
me
> know, it's just that I'm so sick and tired of all of this.
>


--- End Message ---
--- Begin Message ---
What's the best way to pull down XML from a URL?  fopen($URL), then
using xml_parse?  Or should I be using XML_Parser or SimpleXML?

Thanks,
Waynn

--- End Message ---

Reply via email to