php-general Digest 2 Jun 2006 13:49:09 -0000 Issue 4162

Topics (messages 237233 through 237264):

$BG%?1$7$F$^$9(B
        237233 by: yume

Re: Help with enter key in Forms
        237234 by: George Babichev
        237235 by: Chris
        237236 by: Chuck Anderson
        237237 by: George Babichev

Re: OO purism sucks - this is a rant for anyone who     is      allergic to 
that        kind of thing...
        237238 by: Rasmus Lerdorf
        237239 by: John Meyer
        237253 by: Jochem Maas

PHP/Mysql: Making binary field available for download - extra browser window ?
        237240 by: Matthew Pegg
        237241 by: Sichta, Daniel
        237254 by: Jochem Maas

Problem with a script
        237242 by: Ministério Público
        237243 by: Chris
        237246 by: Chris
        237248 by: Ministério Público
        237251 by: Chris

Re: Retrieve Content from URL
        237244 by: Ministério Público
        237245 by: Chris
        237247 by: Ministério Público
        237249 by: Chris
        237250 by: Ministério Público

Re: Extended Ascii Characters
        237252 by: Richard Luckhurst

Reading an XML outputting PHP file as XML
        237255 by: IG
        237262 by: Jochem Maas

If value is odd or not
        237256 by: Jonas Rosling
        237257 by: Dave Goodchild
        237258 by: Brad Bonkoski
        237259 by: Jonas Rosling
        237260 by: IG
        237261 by: Jochem Maas
        237263 by: Jochem Maas
        237264 by: Ford, Mike

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:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
 
 
美香です。妊娠6ヶ月ですが、エッチしませんか。
 
ミルクも出ますよ
 
今はほとんど1日中家にいるので連絡頂ければ何時でも会えます。
 
278424のプロフにアドレスあります。待ってます
 
 
 
 
 
 
 
 
 
 
 
 

--- End Message ---
--- Begin Message ---
Ok, I sent it to everyone and you. Now can you answer my question please?
I type in
1



2
into my form in the program that i made, then when I view it, it shows
1 2
BUT if I check it in PHP My Admin it displays
1



2

So why is my program not showing those spaces?


On 6/1/06, Chris <[EMAIL PROTECTED]> wrote:

George Babichev wrote:
> I can't exactly reply all, because It is only sending it to you. Ok, so
> wait, the data with the spaces (enter keys), but why does my program not
> show it? Look. This is what I mean

In your email program hit "Reply ALL" instead of "Reply".

Until you work out how to do that, I'm going to ignore your emails.

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


--- End Message ---
--- Begin Message ---
George Babichev wrote:
Ok, I sent it to everyone and you. Now can you answer my question please?
I type in
1



2
into my form in the program that i made, then when I view it, it shows
1 2
BUT if I check it in PHP My Admin it displays
1



2

The answer is to change this:

<? echo "".$row['post']."

to this:

<? echo "".nl2br($row['post'])."


like I said before...

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

--- End Message ---
--- Begin Message ---
Chris wrote:
George Babichev wrote:
Hello everyone, I am programming a blog, and most of it is done, except I
have one issue. When I am typing in the form (before I click submit) and I
click the neter key to make a space, the MySQL database does not recognize
that space. How do I make it recognize it?

Unless you're stripping it out, it will recognise it. View HTML Source and you'll see the newline is actually in there. A "\n" is not a html newline so you need to convert it.

What you want is http://php.net/nl2br

Uhhh .... did you try this -- nl2br?

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************

--- End Message ---
--- Begin Message ---
Awesome, thank you so much! It works!

On 6/1/06, Chris <[EMAIL PROTECTED]> wrote:

George Babichev wrote:
> Ok, I sent it to everyone and you. Now can you answer my question
please?
> I type in
> 1
>
>
>
> 2
> into my form in the program that i made, then when I view it, it shows
> 1 2
> BUT if I check it in PHP My Admin it displays
> 1
>
>
>
> 2

The answer is to change this:

<? echo "".$row['post']."

to this:

<? echo "".nl2br($row['post'])."


like I said before...

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


--- End Message ---
--- Begin Message ---
Robert Cummings wrote:

Well there "was" a segfault, but that's fixed now, now the warning is
thrown because of some purist attitude that says it's incorrect to pass
a literal to a reference expecting parameter... I can see how that's an
issue in C with pointers, or in a strongly type language like Java, but
part of PHP's popularity is that while it shares a lot of functions with
C, it is neither C nor Java, but rather a much simpler system that
generally for all the novices out there "works well".

Stuff like this is a bug in your code.  It has nothing to do with purism:

function inc_arg(&$arg) {
  $arg++;
}
inc_arg(3);

You have specifically defined your function to modify the argument yet you pass it something that has no storage and thus there is no way to use that modification. For the most part I agree that we need to keep the language as flexible and forgiving as possible, but where we are able to detect code that obviously doesn't do what the programmer intended, it is tremendously helpful to get a descriptive error.

As far as functions returning references, you are right that returning a literal there sometimes makes sense, but this can also hide a bug which is why this only throws a notice.

You could argue that we could try to look ahead and see what is actually done with the passed argument to see if it is modified, or that we could try to figure out whether the returned reference is actually used as such, but that is technically extremely difficult given the way things work internally. So given the choice between ignoring extremely suspicious code like this and throwing an error/warning, I'd rather be told about it and in the edge cases where I really do want the equivalent of a NOP in my code, it isn't that hard to force it by adding a dummy storage variable along with a comment explaining why you need to do that.

-Rasmus

--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
On Thu, 2006-06-01 at 19:14, Jochem Maas wrote:
Robert Cummings wrote:

Ahh yes, I do like the elegance of prototypes too. They're a different
kind of beast, but a very flexible one.
the more I get in it the pretty it gets - javascript doesn't just give you a
revolver to shoot yourself with it gives you a Doom3 chainsaw and it's shiny :-)

Oh yeah... *rubs the gash in his foot*. I do firmly believe though, that
if you have an iota of intelligence, then shooting yourself in the foot
will lead to a strong lesson learned :) Protecting idiots from
themselves just creates a problem of lots of idiots needing protection
from themselves -- that should be a human resources issue, not a
language issue IMHO :)

Cheers,
Rob.


What was that joke that I heard. While regular programming gives you enough rope to hang yourself, OO lets you design the tree object.
--- End Message ---
--- Begin Message ---
hi Rasmus,

I understand the point you made below - you have made this argument before
and I, for one, accepted it as valid when I first read the discussion
on internals - which is why I avoided ranting about that (and changes like it)

But I am wondering what if any your views might be on the original rant (mine)
regarding purism/strictness that [I feel] is creeping into php for no good
(read 'pragmatic') reason?

as an example - I have in the past argued that discontinuing the ability to
define static methods in interfaces was against the grain and was given the
reply 'you don't understand OO fix your code' - in the last couple of weeks
static interface methods were reintroduced to help in a situation highlighted
by Derick R. I have had pretty much the same experience regarding late static
binding - to which (though nothing to do with my pleas) has finally been 
capitulated
for inclusion in php6.... not inducive to an optimal uptake of php5 which given
the length of time it's been out is rather dismal when compared to the speed at
which php4 was taken up.

if you agree at all with my postulation then maybe you also see some need
to address the issue?

kind regards,
Jochem

Rasmus Lerdorf wrote:
Robert Cummings wrote:

Well there "was" a segfault, but that's fixed now, now the warning is
thrown because of some purist attitude that says it's incorrect to pass
a literal to a reference expecting parameter... I can see how that's an
issue in C with pointers, or in a strongly type language like Java, but
part of PHP's popularity is that while it shares a lot of functions with
C, it is neither C nor Java, but rather a much simpler system that
generally for all the novices out there "works well".


Stuff like this is a bug in your code.  It has nothing to do with purism:

function inc_arg(&$arg) {
  $arg++;
}
inc_arg(3);

You have specifically defined your function to modify the argument yet you pass it something that has no storage and thus there is no way to use that modification. For the most part I agree that we need to keep the language as flexible and forgiving as possible, but where we are able to detect code that obviously doesn't do what the programmer intended, it is tremendously helpful to get a descriptive error.

As far as functions returning references, you are right that returning a literal there sometimes makes sense, but this can also hide a bug which is why this only throws a notice.

You could argue that we could try to look ahead and see what is actually done with the passed argument to see if it is modified, or that we could try to figure out whether the returned reference is actually used as such, but that is technically extremely difficult given the way things work internally. So given the choice between ignoring extremely suspicious code like this and throwing an error/warning, I'd rather be told about it and in the edge cases where I really do want the equivalent of a NOP in my code, it isn't that hard to force it by adding a dummy storage variable along with a comment explaining why you need to do that.

-Rasmus


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

Working on a PHP script at the moment where I want to be able to
extract a file (PDF file) from a mysql database and force the popup
of the File Download dialog, to allow the user to either save or open
the document (ie. and bypass loading the file using the browser's plugin) 

I've found solutions on the net for doing this with a file using readfile()
but if I can get away with it, I don't want to create temporary files...

Here's what I've got so far (truncated...):
    <?
    ..
    // db query string extract the PDF file
    $result = mysql_query("select file_data from brochure where 
id=1",$connection);

    $row    = mysql_fetch_array($result);
    $lengths = mysql_fetch_lengths($result);

    // Grab the file contents as returned from the db
    $pdf_brochure = $row["file_data"];

    // setup headers to force download of $pdf_brochure into crap.pdf
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Type: application/force-download");

    header("Content-Disposition: attachment; filename=\"crap.pdf\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . $lengths[0]);

    // send the file to stdout
    print $pdf_brochure;        // <---- problem might be here.... 
    exit();

    ?>

This almost works but the problem is that this code still spawns a new empty
browser window, and I don't know how to prevent this.... Can anyone help ?


regards,
Matt.

-- 
_______________________________________________
Matt Pegg
IT Specialist
Abacus Business Machines
Ballarat, Australia.
_______________________________________________

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

In this case I usually creating Iframe with zero with and zero height
and using 
your "header" code in the iframe sorce file.

DS

-----Original Message-----
From: Matthew Pegg [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 02, 2006 7:59 AM
To: php-general@lists.php.net
Subject: [PHP] PHP/Mysql: Making binary field available for download -
extra browser window ? 

Hi all,

Working on a PHP script at the moment where I want to be able to
extract a file (PDF file) from a mysql database and force the popup
of the File Download dialog, to allow the user to either save or open
the document (ie. and bypass loading the file using the browser's
plugin) 

I've found solutions on the net for doing this with a file using
readfile()
but if I can get away with it, I don't want to create temporary files...

Here's what I've got so far (truncated...):
    <?
    ..
    // db query string extract the PDF file
    $result = mysql_query("select file_data from brochure where
id=1",$connection);

    $row    = mysql_fetch_array($result);
    $lengths = mysql_fetch_lengths($result);

    // Grab the file contents as returned from the db
    $pdf_brochure = $row["file_data"];

    // setup headers to force download of $pdf_brochure into crap.pdf
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain
browsers
    header("Content-Type: application/force-download");

    header("Content-Disposition: attachment; filename=\"crap.pdf\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . $lengths[0]);

    // send the file to stdout
    print $pdf_brochure;        // <---- problem might be here.... 
    exit();

    ?>

This almost works but the problem is that this code still spawns a new
empty
browser window, and I don't know how to prevent this.... Can anyone help
?


regards,
Matt.

-- 
_______________________________________________
Matt Pegg
IT Specialist
Abacus Business Machines
Ballarat, Australia.
_______________________________________________

--- End Message ---
--- Begin Message ---
Matthew Pegg wrote:
Hi all,

Working on a PHP script at the moment where I want to be able to
extract a file (PDF file) from a mysql database and force the popup
of the File Download dialog, to allow the user to either save or open
the document (ie. and bypass loading the file using the browser's plugin)
I've found solutions on the net for doing this with a file using readfile()
but if I can get away with it, I don't want to create temporary files...

not having temporary files and even the code you use have nothing to do with
the extra window problem - that is a client side issue over which php has no
control .. it's down to the browser settings (possibly) or (more likely) the
target attribute of the link in question.


Here's what I've got so far (truncated...):
    <?
    ..
    // db query string extract the PDF file
    $result = mysql_query("select file_data from brochure where 
id=1",$connection);

    $row    = mysql_fetch_array($result);
    $lengths = mysql_fetch_lengths($result);

    // Grab the file contents as returned from the db
    $pdf_brochure = $row["file_data"];

    // setup headers to force download of $pdf_brochure into crap.pdf
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Type: application/force-download");

    header("Content-Disposition: attachment; filename=\"crap.pdf\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . $lengths[0]);

    // send the file to stdout
print $pdf_brochure; // <---- problem might be here.... exit();

    ?>

This almost works but the problem is that this code still spawns a new empty
browser window, and I don't know how to prevent this.... Can anyone help ?

don't open a new window to download it then ... i.e. don't use 
'target="_blank"' in
the html defintion of the relevant link.



regards,
Matt.


--- End Message ---
--- Begin Message ---
Hi guys I'm getting the following error and I cant seem to understand what
Im doing wrong, if someone could help me I'd apreciate it.

Here is the error message I get in some fileds of the output on the browser:

*Warning*: Invalid argument supplied for foreach() in *
c:\apache\htdocs\pobs\pobs.php* on line *180*
**
*And here goes the lines I've put a few before and a few after just in case.
*
**
**
**
*178

<TR><TD valign="bottom">JavaScript (Functions & Variables)</TD><TD WIDTH=10
valign="top">&nbsp;</TD><TD><input type="checkbox" name="ReplaceJS"
value="1" checked>&nbsp;&nbsp;
*
*179*

<? echo *"+ files with extensions: ";
*
*180*

*foreach($JSFileExtArray* as *$Key* *=>* *$Value)
*
*181*

echo *'<b>'.$Value.'</b>,';
*
*182*

?>

--- End Message ---
--- Begin Message ---
Ministério Público wrote:
Hi guys I'm getting the following error and I cant seem to understand what
Im doing wrong, if someone could help me I'd apreciate it.

Here is the error message I get in some fileds of the output on the browser:

*Warning*: Invalid argument supplied for foreach() in *
c:\apache\htdocs\pobs\pobs.php* on line *180*

..

*foreach($JSFileExtArray* as *$Key* *=>* *$Value)

JSFileExtArray isn't an array, it's something else.

Use var_dump to see what it is and go from there.

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

--- End Message ---
--- Begin Message ---
Ministério Público wrote:
After using the var_dump the only thing I get is NULL, therefore I'll try something else that I think is more complete for the fellow programmers.

Nobody's going to trawl through all of your code.

Narrow down where the problem is.

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

--- End Message ---
--- Begin Message ---
I showed where the problem is and after var_dump all I get is NULL. I just
sent the code cause I thought it would be easier to see it in context, not
to make somebody trawl trough it. If its not an array how to find out what
it is? What can I do about it?
Thanks.
Rodrigo

--- End Message ---
--- Begin Message ---
Ministério Público wrote:

I showed where the problem is and after var_dump all I get is NULL. I just sent the code cause I thought it would be easier to see it in context, not to make somebody trawl trough it. If its not an array how to find out what it is? What can I do about it?

Put debug lines throughout your code and see where it breaks.

eg:

echo "at line " . __LINE__ . ", var is " . gettype($JSFileExtArray) . "<br/>";

do that every 20 lines and then narrow the problem down from there.

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

--- End Message ---
--- Begin Message ---
What I need to know is that if when I fopen() or the other function you gave
me I get the variables that are assigned on the html, such as the option for
example, if its name is "test", could I access it retrieving the value $test
???

cause I really need to do it and I cant seem to know where to begin.

Thanks in advance,
Rodrigo

--- End Message ---
--- Begin Message ---
Ministério Público wrote:
What I need to know is that if when I fopen() or the other function you gave me I get the variables that are assigned on the html, such as the option for example, if its name is "test", could I access it retrieving the value $test ???

No. Those functions will retrieve the webpage exactly the same as your browser does.

What would "test" be? Provide an example of what you see and what you are trying to end up with.

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

--- End Message ---
--- Begin Message ---
Here it goes: in a certain page there is a dinamicaly generated Option ( one
of those boxes from wich you can select a certain thing in a list) I want to
retrieve the content of these options and the values assigned to each of
them.

Thanx.
Rodrigo

--- End Message ---
--- Begin Message ---
Ministério Público wrote:
Here it goes: in a certain page there is a dinamicaly generated Option ( one of those boxes from wich you can select a certain thing in a list) I want to retrieve the content of these options and the values assigned to each of them.

So if you have:

<option value="test1">Test 1</option>
<option value="test2">Test 2</option>

You want:

$test1 = "Test 1";
$test2 = "Test 2";

??

preg_match_all('%<option value=["\']*([^"\'>]+?)["\']*\s*>(.*)</option>%isU', $text, $matches);

That will give you an array that looks like this:

Array
(
    [0] => Array
        (
            [0] => <option value="test1">Test 1</option>
            [1] => <option value="test2">Test 2</option>
        )

    [1] => Array
        (
            [0] => test1
            [1] => test2
        )

    [2] => Array
        (
            [0] => Test 1
            [1] => Test 2
        )

)

From there you should be able to work out what to do..

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

--- End Message ---
--- Begin Message ---
Chris you rule !!!

That great from here I'll be abble to go on.

Thanks.
Rodrigo

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

I had a hunt in the archives and couldn't find anything. Do you have any clue
about when it was?

Richard

t> At 9:46 AM +1000 6/2/06, Richard Luckhurst wrote:
>>Hi All
>>
>>I am in the process of cleaning up an application that was left half 
>>finished. I
>>am fairly new to PHP so I am seeking the wisdom of the community to help with 
>>a
>>little problem.
>>
>>In many cases I need to build command strings to be sent to a backend system.
>>The strings have to contain a couple of non ascii characters.
>>
>>I have no problem with the following in a script
>>
>>$RM="\xFF";
>>
>>Then using the variable works fine within that chunk of php code.
>>
>>What I would like to do is place all of the extended ascii characters in one 
>>of
>>the inc files and just use these in various scripts throughout the 
>>application.
>>
>>When I try what I get is a test representation rather than the actual ascii
>>code. Ie I get \xFF instead of the ascii character ÿ
>>
>>Is there any way to actually do this in php?
>> 
>>
>>
>>Regards,
>>Richard Luckhurst                     
>>Product Development


t> Yes, I think there is  -- we discussed this a few months ago on this list 
and someone wrote a routine to do basically want you want, or so I think -- so 
check the archives.

t> tedd

t> -- 
t> 
------------------------------------------------------------------------------------
t> http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hi.
I have a PHP file that outputs as XML from a database. i have used the header() function to output the correct header but when I use the simplexml function it is trying to parse the php file itself and not the output of the php file. I can't get my head round this. Can anyone help me?
--- End Message ---
--- Begin Message ---
IG wrote:
Hi.
I have a PHP file that outputs as XML from a database. i have used the header() function to output the correct header but when I use the simplexml function it is trying to parse the php file itself and not the output of the php file. I can't get my head round this. Can anyone help me?

your running the simplexml function on the php file and not its output.



--- End Message ---
--- Begin Message ---
Hi all,
is there any easy why to check if a value is odd or not?

Thanks // Jonas

--- End Message ---
--- Begin Message ---
On 02/06/06, Jonas Rosling <[EMAIL PROTECTED]> wrote:

Hi all,
is there any easy why to check if a value is odd or not?

Thanks // Jonas

Yep, use the modulo operator like so:



if  ($value %  2  ==0)  $odd = false;




--
http://www.web-buddha.co.uk

dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml, css)

look out for project karma, our new venture, coming soon!

--- End Message ---
--- Begin Message ---
if ($value % 2 == 0 )
   echo "Value is even";
else
   echo "Value is odd";

Jonas Rosling wrote:

Hi all,
is there any easy why to check if a value is odd or not?

Thanks // Jonas


--- End Message ---
--- Begin Message ---
-----Ursprungligt meddelande-----
Fran: Eric Mol [mailto:[EMAIL PROTECTED]
Skickat: den 2 juni 2006 15:34
Till: 'Jonas Rosling'; 'PHP List'
Amne: RE: [PHP] If value is odd or not


If ($var/2==round($var/2)){
  // not odd
}else{
  // odd
}

Greetings,
Eric

Thanks (all)!

-----Oorspronkelijk bericht-----
Van: Jonas Rosling [mailto:[EMAIL PROTECTED] 
Verzonden: vrijdag 2 juni 2006 15:32
Aan: PHP List
Onderwerp: [PHP] If value is odd or not

Hi all,
is there any easy why to check if a value is odd or not?

Thanks // Jonas

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

--- End Message ---
--- Begin Message ---
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?

Thanks // Jonas

$value = 3;
if (strpos(($value/2),".") === FALSE) {echo "even";}
                        else {echo "odd";}

--- End Message ---
--- Begin Message ---
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?

the modulos operator:

read about what it does here:
http://php.net/manual/en/language.operators.arithmetic.php

here is a simple example of how to check if something
is odd or not (odd number that is ;-):

$x = 1;
$y = 2;
$z = 3;

var_dump(($x % 2), ($y % 2), ($z % 2));


Thanks // Jonas


--- End Message ---
--- Begin Message ---
Jonas Rosling wrote:
Hi all,
is there any easy why to check if a value is odd or not?

ignore every answer that doesn't use the % operator.


Thanks // Jonas


--- End Message ---
--- Begin Message ---
On 02 June 2006 14:32, Jonas Rosling wrote:

> Hi all,
> is there any easy why to check if a value is odd or not?

   if ($value%2):
      // $value is odd
   endif;

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---

Reply via email to