php-general Digest 10 Aug 2007 08:15:47 -0000 Issue 4953

Topics (messages 260523 through 260553):

Re: I know this is not easy and I'm not stupid but...
        260523 by: Jim Lucas
        260540 by: Jan Reiter
        260542 by: Jim Lucas
        260543 by: Jan Reiter
        260544 by: Phil Curry
        260547 by: Jan Reiter

Re: Forwarding $_POST[]...
        260524 by: Stut
        260525 by: Simon
        260526 by: Jay Blanchard
        260528 by: Richard Heyes
        260529 by: Jim Lucas
        260530 by: Daniel Brown
        260531 by: Daniel Brown
        260538 by: Jim Lucas

Re: ADODB Insert Question (Syntax)
        260527 by: Jim Lucas

Open Source Job Wanted system
        260532 by: Joey
        260533 by: Robert Cummings
        260534 by: Tom Ray [Lists]
        260535 by: Nathan Nobbe

string as file
        260536 by: Rick Pasotto
        260537 by: Greg Donald
        260539 by: Jim Lucas

preg_match_all to match <img> tags
        260541 by: Ólafur Waage
        260549 by: brian
        260552 by: Jan Reiter

Re: get and post together
        260545 by: Daevid Vincent

Re: permissions for include()
        260546 by: jekillen

Re: Sorting files in a directory
        260548 by: Chad Robinson

Re: your excel document
        260550 by: sla-list.lists.sla.org

Re: Access parent property from child
        260551 by: Suprie

Read me!
        260553 by: Ricky Tuttle

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 ---
Stut wrote:
Please include the list when replying.

Phil Curry wrote:
Phil Curry wrote:
how can this be? This is not the first time I've run into a situation like this. What am I missing?
line 102    echo  ($userValues['afterDark']);             // outputs 1
line 103    if ( $userValues['afterDark'] == 0 ) {        // passes

Add a line at 102.5...

var_dump($userValues['afterDark']);

What type is that variable?

Don't have to do a dump, I know its a tinyint(1), not null, default 0

PHP does not have a type of tinyint

knowing now that this comes from a database, if it is mysql, then it is of type 
string

PHP converts all fields when pulled from the database into strings. It does not take into account what type the field is actually set to in mysql.

Try puting a (int) in front of the condition like this

if ( (int)$userValues['afterDark'] == 0 ) {
        ...
}

Maybe this will help


That would be the type in the database, not the type of that variable at that time.

-Stut



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

--- End Message ---
--- Begin Message ---
Hi!

Phil:
Still I am curious what var_dump($userValues['afterDark']); at line 102.5
would return. 
I managed to recreate that fault with 

$var['test'] = "blah";

echo ($var['test']);

if( $var['test'] == 0)
{
        echo "ok";
}

//this returns blahok -- not expected. 

In my case Var_dump() returns string(4) "blah" as expected.

Using 

if( $var['test'] === 0)

behaves as expected!!


Jim:
TypeCasting would only be effective if you used the type sensitive
comparison operator === , because with "==" 0 equals NULL equals false
equals "" and so on ... or do I miss something here??


Hope that solves it for you! I'm still investigating why my first examples
fails. I've got the strong feeling that I'm missing something there. I don't
believe in a php bug or a memory leak in this case! Must be something pretty
obvious! Anyone a clue??

Thanks,
Jan


-----Original Message-----
From: Jim Lucas [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 09, 2007 8:08 PM
To: Stut
Cc: Phil Curry; php-general
Subject: Re: [PHP] I know this is not easy and I'm not stupid but...

Stut wrote:
> Please include the list when replying.
> 
> Phil Curry wrote:
>>> Phil Curry wrote:
>>>> how can this be? This is not the first time I've run into a 
>>>> situation like this. What am I missing?
>>>> line 102    echo  ($userValues['afterDark']);             // outputs 1
>>>> line 103    if ( $userValues['afterDark'] == 0 ) {        // passes
>>>
>>> Add a line at 102.5...
>>>
>>> var_dump($userValues['afterDark']);
>>>
>>> What type is that variable?
>>
>> Don't have to do a dump, I know its a tinyint(1), not null, default 0

PHP does not have a type of tinyint

knowing now that this comes from a database, if it is mysql, then it is of
type string

PHP converts all fields when pulled from the database into strings.  It does
not take into account 
what type the field is actually set to in mysql.

Try puting a (int) in front of the condition like this

if ( (int)$userValues['afterDark'] == 0 ) {
        ...
}

Maybe this will help

> 
> That would be the type in the database, not the type of that variable at 
> that time.
> 
> -Stut
> 


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

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

--- End Message ---
--- Begin Message ---
Jan Reiter wrote:
Hi!

Phil:
Still I am curious what var_dump($userValues['afterDark']); at line 102.5
would return. I managed to recreate that fault with
$var['test'] = "blah";

echo ($var['test']);

if( $var['test'] == 0)
{
        echo "ok";
}

//this returns blahok -- not expected.
In my case Var_dump() returns string(4) "blah" as expected.

Using
if( $var['test'] === 0)

behaves as expected!!

Are you wanting to only test for a empty/non-empty string?

if so, use this.

if ( empty($var['test']) ) {
        echo "var['test'] is empty";
}



Jim:
TypeCasting would only be effective if you used the type sensitive
comparison operator === , because with "==" 0 equals NULL equals false
equals "" and so on ... or do I miss something here??


Hope that solves it for you! I'm still investigating why my first examples
fails. I've got the strong feeling that I'm missing something there. I don't
believe in a php bug or a memory leak in this case! Must be something pretty
obvious! Anyone a clue??

Thanks,
Jan


-----Original Message-----
From: Jim Lucas [mailto:[EMAIL PROTECTED] Sent: Thursday, August 09, 2007 8:08 PM
To: Stut
Cc: Phil Curry; php-general
Subject: Re: [PHP] I know this is not easy and I'm not stupid but...

Stut wrote:
Please include the list when replying.

Phil Curry wrote:
Phil Curry wrote:
how can this be? This is not the first time I've run into a situation like this. What am I missing?
line 102    echo  ($userValues['afterDark']);             // outputs 1
line 103    if ( $userValues['afterDark'] == 0 ) {        // passes
Add a line at 102.5...

var_dump($userValues['afterDark']);

What type is that variable?
Don't have to do a dump, I know its a tinyint(1), not null, default 0

PHP does not have a type of tinyint

knowing now that this comes from a database, if it is mysql, then it is of
type string

PHP converts all fields when pulled from the database into strings.  It does
not take into account what type the field is actually set to in mysql.

Try puting a (int) in front of the condition like this

if ( (int)$userValues['afterDark'] == 0 ) {
        ...
}

Maybe this will help

That would be the type in the database, not the type of that variable at that time.

-Stut





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

--- End Message ---
--- Begin Message ---
Hi! 
Thank you for your response! 

The only intention of my code was to investigate the (back then) unexpected
behavior of the if statement. 


With $var['test'] set to "blah" this expression should be false
($var['test'] == 0) for what I know ...

$var['test'] = "blah";
var_dump($var['test'] == 0); 

//returns bool(true)

Now I know why this happens! According to Table 6.5 of the Operators page in
the PHP Manual in this comparison all of the values are converted to
integer. And  atoi("blah") for sure will fail!;-) So you have to use === to
keep the types of the values! 

Jan



-----Original Message-----
From: Jim Lucas [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 10, 2007 1:47 AM
To: Jan Reiter
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [PHP] I know this is not easy and I'm not stupid but...

Jan Reiter wrote:
> Hi!
> 
> Phil:
> Still I am curious what var_dump($userValues['afterDark']); at line 102.5
> would return. 
> I managed to recreate that fault with 
> 
> $var['test'] = "blah";
> 
> echo ($var['test']);
> 
> if( $var['test'] == 0)
> {
>       echo "ok";
> }
> 
> //this returns blahok -- not expected. 
> 
> In my case Var_dump() returns string(4) "blah" as expected.
> 
> Using 
> 
> if( $var['test'] === 0)
> 
> behaves as expected!!

Are you wanting to only test for a empty/non-empty string?

if so, use this.

if ( empty($var['test']) ) {
        echo "var['test'] is empty";
}

> 
> 
> Jim:
> TypeCasting would only be effective if you used the type sensitive
> comparison operator === , because with "==" 0 equals NULL equals false
> equals "" and so on ... or do I miss something here??
> 
> 
> Hope that solves it for you! I'm still investigating why my first examples
> fails. I've got the strong feeling that I'm missing something there. I
don't
> believe in a php bug or a memory leak in this case! Must be something
pretty
> obvious! Anyone a clue??
> 
> Thanks,
> Jan
> 
>

--- End Message ---
--- Begin Message ---
Please include the list when replying.

Phil Curry wrote:
Phil Curry wrote:
how can this be? This is not the first time I've run into a situation like this. What am I missing? line 102 echo ($userValues['afterDark']); // outputs 1
line 103    if ( $userValues['afterDark'] == 0 ) {        // passes

Add a line at 102.5...

var_dump($userValues['afterDark']);

What type is that variable?
Don't have to do a dump, I know its a tinyint(1), not null, default 0

That would be the type in the database, not the type of that variable at that time.

-Stut

--
http://stut.net/

Absolutely right. didn't think of that.

var_dump($userValues['afterDark']);  ==> string(1) "1"

but then I'm comparing a string to an int and the result always seems to pass. So does that mean any string compared to any int will be true? By casting (int)$userValues['afterDark'] the test still passes and var_dump shows the (int)$userValues['afterDark'] as an int(1) but does give a value like the previous example. ie. string(1)"1" but only int(1) Not sure if the expression has a value of "1" now that its been cast.

Then finally if ( (int)$userValues['afterDark'] === 0 ) { // passes

So:
if ( $userValues['afterDark'] == 0 ) {                  // passes
if ( (int)$userValues['afterDark'] == 0 ) {           // passes
if ( (int)$userValues['afterDark'] === 0 ) {         // passes

And the value of afterdark in the mysql table is tinyint(1) 1.
And echo( 1+(int)$userValues['afterDark']);    // outputs 2

Now I'm confused!
-Phil

--- End Message ---
--- Begin Message ---
Ummh, no!

(int) and (integer) perform a C style atoi() conversion. 

(int)"blah" => integer 0
(int)"" => integer 0
(int)"1"        => integer 1
(int)"12"       => integer 12

 ("1" == 0)     => false
 ("blah" == 0)  => true

( (int)$userValues['afterDark'] === 0 ) only is true, if
$userValues['afterDark'] is a string not containing an integer. This is what
happens:

$userValues['afterDark'] gets converted to integer by atoi(), and after that
is compared by type and value to integer 0. So the type part of the test
will pass for sure. 

But perhaps you should try to adapt the comparison to the DB value. So try
($userValues['afterDark'] == (string)0)
This expression is only true if $userValues['afterDark'] equals "0", not
when $userValues['afterDark'] equals "" or "blah" or "1"

Hope that helps!

Jan


-----Original Message-----
From: Phil Curry [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 10, 2007 2:49 AM
To: Stut
Cc: php-general
Subject: Re: [PHP] I know this is not easy and I'm not stupid but...

> Please include the list when replying.
>
> Phil Curry wrote:
>>> Phil Curry wrote:
>>>> how can this be? This is not the first time I've run into a  
>>>> situation like this. What am I missing?
>>>> line 102    echo  ($userValues['afterDark']);             //  
>>>> outputs 1
>>>> line 103    if ( $userValues['afterDark'] == 0 ) {        // passes
>>>
>>> Add a line at 102.5...
>>>
>>> var_dump($userValues['afterDark']);
>>>
>>> What type is that variable?
>> Don't have to do a dump, I know its a tinyint(1), not null, default 0
>
> That would be the type in the database, not the type of that  
> variable at that time.
>
> -Stut
>
> -- 
> http://stut.net/

Absolutely right. didn't think of that.

var_dump($userValues['afterDark']);  ==> string(1) "1"

but then I'm comparing a string to an int and the result always seems  
to pass. So does that mean any string compared to any int will be true?
By casting (int)$userValues['afterDark'] the test still passes and  
var_dump shows the (int)$userValues['afterDark'] as an int(1) but  
does give a value like the previous example.
ie. string(1)"1" but only int(1) Not sure if the expression has a  
value of "1" now that its been cast.

Then finally  if ( (int)$userValues['afterDark'] === 0 ) {        //  
passes

So:
if ( $userValues['afterDark'] == 0 ) {                  // passes
if ( (int)$userValues['afterDark'] == 0 ) {           // passes
if ( (int)$userValues['afterDark'] === 0 ) {         // passes

And the value of afterdark in the mysql table is tinyint(1) 1.
And echo( 1+(int)$userValues['afterDark']);    // outputs 2

Now I'm confused!
-Phil

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

--- End Message ---
--- Begin Message ---
Tony Di Croce wrote:
I keep wanting to do something, and either I dont know how to do it, or I'm
doing something wrong and need to rethink things.

Quite often, I have a form that submits to a php script via POST and after
doing some processing (or more frequently, asking the user a question), I'd
like to forward those $_POST[] vars to another script (or even the same
script).

Sounds like an architectural issue to me. Think about why you want to do this. Can you not just include the other script rather than causing another HTTP request?

I could do something complicated and store the $_POST vars in $_SESSION[],
but what I'd rather do is simply add a var to $_POST[] and resubmit this to
the same .php.

Let me get this straight... you want to add a variable to the $_POST array and then re-run the current script? Put the functionality you need into a function and then use standard control structures (while, if, foreach, etc) to call it over and over again if necessary. There's absolutely no need to cause another HTTP request.

Is their any way to do this, or do I need to rethink things?

Rethink things. There's almost certainly a better way but without knowing why you think you need to do this it's not possible to help any further.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
Session variables is a decent way.
Storing them in a DB session can be good too
It all depends on the data.

The dumbest (but still correct) way to do it is a for() loop that
creates a hidden input with the name/value pair for each variables you
want.

I would advise against resending the username/password over and over.

Simon

On 8/9/07, Tony Di Croce <[EMAIL PROTECTED]> wrote:
> I keep wanting to do something, and either I dont know how to do it, or I'm
> doing something wrong and need to rethink things.
>
> Quite often, I have a form that submits to a php script via POST and after
> doing some processing (or more frequently, asking the user a question), I'd
> like to forward those $_POST[] vars to another script (or even the same
> script).
>
> I could do something complicated and store the $_POST vars in $_SESSION[],
> but what I'd rather do is simply add a var to $_POST[] and resubmit this to
> the same .php.
>
> Is their any way to do this, or do I need to rethink things?
>
>    td
>
> --
> Publish technical articles @ skilledwords.com and get 100% of the
> ad-revenue!
> http://www.skilledwords.com
>

--- End Message ---
--- Begin Message ---
[snip]
I could do something complicated and store the $_POST vars in
$_SESSION[],
but what I'd rather do is simply add a var to $_POST[] and resubmit this
to
the same .php.

Is their any way to do this, or do I need to rethink things?
[/snip]

Put the processing in a function, run the post variables through the
function. Create another array to hold the post variables and add
another variable and send that array to the function.

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

I could do something complicated and store the $_POST vars in $_SESSION[],
but what I'd rather do is simply add a var to $_POST[] and resubmit this to
the same .php.

Is their any way to do this, or do I need to rethink things?

There's nothing complicated about using sessions.

<?php

  session_start();
  $_SESSION['post_data'] = $_POST;

?>

--
Richard Heyes
+44 (0)844 801 1072
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--- End Message ---
--- Begin Message ---
Tony Di Croce wrote:
I keep wanting to do something, and either I dont know how to do it, or I'm
doing something wrong and need to rethink things.

Quite often, I have a form that submits to a php script via POST and after
doing some processing (or more frequently, asking the user a question), I'd
like to forward those $_POST[] vars to another script (or even the same
script).

I could do something complicated and store the $_POST vars in $_SESSION[],
but what I'd rather do is simply add a var to $_POST[] and resubmit this to
the same .php.

Is their any way to do this, or do I need to rethink things?

   td

What is complicated about

step1.php
<?php

$my_post_data = $_POST;

...

$_SESSION['_POST'] = $my_post_data;

?>
and
step2.php
<?php

$my_post_data = $_SESSION['_POST'];

...

?>

I see nothing about this that is complicated.  Where do you see the 
complication?

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

--- End Message ---
--- Begin Message ---
On 8/9/07, Tony Di Croce <[EMAIL PROTECTED]> wrote:
> I keep wanting to do something, and either I dont know how to do it, or I'm
> doing something wrong and need to rethink things.
>
> Quite often, I have a form that submits to a php script via POST and after
> doing some processing (or more frequently, asking the user a question), I'd
> like to forward those $_POST[] vars to another script (or even the same
> script).
>
> I could do something complicated and store the $_POST vars in $_SESSION[],
> but what I'd rather do is simply add a var to $_POST[] and resubmit this to
> the same .php.
>
> Is their any way to do this, or do I need to rethink things?
>
>    td
>
> --
> Publish technical articles @ skilledwords.com and get 100% of the
> ad-revenue!
> http://www.skilledwords.com
>

    You can do either one, Tony --- rethink or go ahead with it.

    Check out the cURL functions if you want to forward the variables
as a POST to a different script.  Otherwise, if you're just trying to
add new values to the $_POST array to be processed further down the
script, simply add them.

<?
    $_POST['new_name'] = "new value";
?>

-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Hey, PHP-General list....
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.

--- End Message ---
--- Begin Message ---
On 8/9/07, Jim Lucas <[EMAIL PROTECTED]> wrote:
> What is complicated about
>
> step1.php
> <?php
>
> $my_post_data = $_POST;
>
> ...
>
> $_SESSION['_POST'] = $my_post_data;
>
> ?>
> and
> step2.php
> <?php
>
> $my_post_data = $_SESSION['_POST'];
>
> ...
>
> ?>

    Jim, perhaps I'm missing something that you're hinting at,
represented by the ellipsis, but why redefine the superglobal to a
transient variable prior to populating the session?


-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Hey, PHP-General list....
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.

--- End Message ---
--- Begin Message ---
Daniel Brown wrote:
On 8/9/07, Jim Lucas <[EMAIL PROTECTED]> wrote:
What is complicated about

step1.php
<?php

$my_post_data = $_POST;

...

perhaps you want to have a clean data set
you can do this as you populate the $my_post_data
let me rename variable

<?php

//This allows you to only have to clean the post data once.
//Then upon reuse in step2.php, you don't have to clean data a second time.
$clean_post_data = cleanup_input_data($_POST);
$_SESSION['_POST'] = $clean_post_data;

//You should never work with raw $_POST or $_GET data
//You should always clean first then use the data.  Storing it in a different 
array,
//not back in the $_POST and/or $_GET arrays and overwriting the original data.
...  working with $clean_post_data ...

?>


$_SESSION['_POST'] = $clean_post_data;

?>
and
step2.php
<?php

$my_post_data = $_SESSION['_POST'];

this data is supposedly clean, some would say that it is best to assume that the data is might be tainted, but I have always assumed that nobody is actually going to modify the session data files directly and inject harmful data into the session file itself.

But some would say, even re-clean the data that you pull from your sessions, because you never know how someone might try and mess with you.



...

?>

    Jim, perhaps I'm missing something that you're hinting at,
represented by the ellipsis, but why redefine the superglobal to a
transient variable prior to populating the session?




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

--- End Message ---
--- Begin Message ---
Graham Anderson wrote:
Wow.  I feel really dumb.
I thought (incorrectly) that the surrounding quotes would screw with the variables in the ADODB's INSERT statement.

many thanks
G

On Aug 7, 2007, at 2:06 PM, Uber Wannabe wrote:

-----Original Message-----
From: Graham Anderson [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 07, 2007 3:34 PM
To: php-general
Subject: [PHP] ADODB Insert Question (Syntax)

Hi

What is the proper way to get the ADODB class to automatically add
quotes to the below sql ?
I'm guessing that the below fails because none of the variables get
quoted with the method, qstr.

$sql = "insert into email (to_name, to_email, from_name, from_email,
subject, message, timestamp, ip) ";
$sql .= "values ($to_name, $to_email, $from_name, $from_email,
$subject, $message, $time, $ip)";


I tried something like the below to no avail
$sql .= "values($conn->qstr($to_name), $conn->qstr
($to_email), .......)";


Is there an accepted way to place multiple $variables inside an ADODB
insert statement?

many thanks

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

-----End Original Message-----


Okay, I'm probably missing something, but why can't the values portion just
say:

"values ('$to_name', '$to_email', '$from_name',... etc.

hold on now. you might want to make sure and escape data before you just throw it into the query like that.

His method was just fine, but the problem is is that the $obj->method() thing wont work in a quoted string.

If he had E_NOTICE turned on, he would see the error.

what needs to happen is that he needs to break out of the double quotes and concat the string(s) and method calls together like this.

$sql .= "values(".$conn->qstr($to_name).", ".$conn->qstr($to_email).", 
.......)";


... with the single quotes around the variable names?


-- N/A





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

--- End Message ---
--- Begin Message ---
Has anybody had any experience with any open source Job posting systems out
there?

 

Thanks!

 

 

--- End Message ---
--- Begin Message ---
On Thu, 2007-08-09 at 14:54 -0400, Joey wrote:
> Has anybody had any experience with any open source Job posting systems out
> there?

I didn't get the job *sniffle*.

:B

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

--- End Message ---
--- Begin Message ---
Joey wrote:
Has anybody had any experience with any open source Job posting systems out
there?

Thanks!

I've written one myself. It allows for job seekers to put up a profile, resumes, etc and for employers to post their jobs and search resumes. Full search ability on both sides. They can even opt for "Hot Resumes" or "Hot Jobs" for higher/preferred listings in the search.

I'm not sure what else is really out there. I guess it will all depend on what you're looking to do.
--- End Message ---
--- Begin Message ---
craigslist is out there, but i havent posted a resume on there..

-nathan

On 8/9/07, Joey <[EMAIL PROTECTED]> wrote:
>
> Has anybody had any experience with any open source Job posting systems
> out
> there?
>
>
>
> Thanks!
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Does php have a facility similar to python's stringIO?

What I'm wanting to do is similar to a mail merge. IOW, I know I can
create an include file like:

$out = <<<EOT
This is an example of $var1 and $var2.
EOT;

and then after assigning values to $var1 and $var2 include that file. I
can later use different values for $var1 and $var2 and get a different
$out with a second include.

Can I someout "include" a string instead of a file? Or maybe there is
some completely different way to do what I want.

-- 
"I have always in my own thought summed up individual liberty, and
 business liberty, and every other kind of liberty, in the phrase
 that is common in the sporting world, "A free field and no favor."
        -- Woodrow Wilson, U.S. President, 1915
    Rick Pasotto    [EMAIL PROTECTED]    http://www.niof.net

--- End Message ---
--- Begin Message ---
On 8/9/07, Rick Pasotto <[EMAIL PROTECTED]> wrote:
> Does php have a facility similar to python's stringIO?
>
> What I'm wanting to do is similar to a mail merge. IOW, I know I can
> create an include file like:
>
> $out = <<<EOT
> This is an example of $var1 and $var2.
> EOT;
>
> and then after assigning values to $var1 and $var2 include that file. I
> can later use different values for $var1 and $var2 and get a different
> $out with a second include.

eval()


-- 
Greg Donald
http://destiney.com/

--- End Message ---
--- Begin Message ---
Rick Pasotto wrote:
Does php have a facility similar to python's stringIO?

What I'm wanting to do is similar to a mail merge. IOW, I know I can
create an include file like:

$out = <<<EOT
This is an example of $var1 and $var2.
EOT;

and then after assigning values to $var1 and $var2 include that file. I
can later use different values for $var1 and $var2 and get a different
$out with a second include.

Can I someout "include" a string instead of a file? Or maybe there is
some completely different way to do what I want.

template.php
<?php

ob_start();
echo "Hi, my name is {$first_name} {$last_name}.";
return ob_get_clean();

?>


This is two different ways you can do it, bases on your input data array 
structure

test.php
<?php

$values = array();

$values[] = array('first_name' => 'Jim','last_name' => 'Lucas');
$values[] = array('first_name' => 'James','last_name' => 'Lucas');
$values[] = array('first_name' => 'Jimmy','last_name' => 'Lucas');

foreach ($values AS $row) {
        extract($row);
        echo include 'template.php';
}

$values = array();

$values[] = array('Jim','Lucas');
$values[] = array('James','Lucas');
$values[] = array('Jimmy','Lucas');

list($first_name, $last_name) = current($values);
do {
        echo include 'template.php';
} while (list($first_name, $last_name) = next($values));
?>

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

--- End Message ---
--- Begin Message ---
I know this isn't exactly a php related question but due to the
quality of answers ive seen lately ill give this a shot. (yes yes im
smoothing up the crowd before the question)

I have a weblog system that i am creating, the trouble is that if a
user links to an external image larger than 500pixels in width, it
messes with the whole layout.

I had found some regex code im using atm but its not good at matching
the entire image tag. It seems to ignore properties after the src
declaration and not match tags that have properties before the src
declaration .

preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i",
$data, $matches);
print_r($matches);

This currently makes two arrays for me, the source location from all
img tags and a large part of the tag itself. But not the entire tag.

What i do is i match the img tag, find the src, get the image
properties, and if the width is more than 500, i shrink it down and
add width="X" and height="Y" properties to the image tag.

How can i match an image tag correctly so it does not cause any issues
with how the user adds the image.

--- End Message ---
--- Begin Message ---
Ólafur Waage wrote:
I know this isn't exactly a php related question but due to the
quality of answers ive seen lately ill give this a shot. (yes yes im
smoothing up the crowd before the question)

I have a weblog system that i am creating, the trouble is that if a
user links to an external image larger than 500pixels in width, it
messes with the whole layout.

I had found some regex code im using atm but its not good at matching
the entire image tag. It seems to ignore properties after the src
declaration and not match tags that have properties before the src
declaration .

preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i",
$data, $matches);
print_r($matches);

This currently makes two arrays for me, the source location from all
img tags and a large part of the tag itself. But not the entire tag.

What i do is i match the img tag, find the src, get the image
properties, and if the width is more than 500, i shrink it down and
add width="X" and height="Y" properties to the image tag.

How can i match an image tag correctly so it does not cause any issues
with how the user adds the image.


<style>
#your_content_div img { max-width: 500px !important; }
</style>

OK, so it won't work with IE6. Screw them.

But if the height is set in the img tag it'll keep that, so the image could become distorted. So, you could also do something like:

#your_content_div img { visibility: none; }

Then run some Javascript routine onload to properly figure the dimensions of each image. Adjust the width down to 500px, if necessary, then the height by whatever percent difference between original width over new width:

var new_height = (original_width / 500) * original_height;

Then, whether you change the dimensions of the image or not, change the visibility of each to 'visible'.

So, um ... no PHP involved.

brian

--- End Message ---
--- Begin Message ---
Maybe this is what you are searching for:

$images = array();
$data = "blah <img src=img.png width=\"400\" height='600'> src=blah.png <img
src=gg.tiff>";

preg_match_all("/\< *[img][^\>]*[.]*\>/i", $data, $matches);
foreach($matches[0] as $match)
{
        preg_match_all("/(src|height|width)*= *[\"\']{0,1}([^\"\'\ \>]*)/i",
$match, $m);
        $images[] = array_combine($m[1],$m[2]);
}

print_r($image);

It will produce:

Array 
( 
        [0] => Array 
        ( 
                [src] => img.png 
                [width] => 400 
                [height] => 600 
        ) 

        [1] => Array 
        ( 
                [src] => gg.tiff 
        )
)

I wrote it just as an example. So you may modify it for your needs!
Does anyone know if there is a way to put this into ONE regex??

Jan

-----Original Message-----
From: brian [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 10, 2007 3:18 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] preg_match_all to match <img> tags

Ólafur Waage wrote:
> I know this isn't exactly a php related question but due to the
> quality of answers ive seen lately ill give this a shot. (yes yes im
> smoothing up the crowd before the question)
> 
> I have a weblog system that i am creating, the trouble is that if a
> user links to an external image larger than 500pixels in width, it
> messes with the whole layout.
> 
> I had found some regex code im using atm but its not good at matching
> the entire image tag. It seems to ignore properties after the src
> declaration and not match tags that have properties before the src
> declaration .
> 
> preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i",
> $data, $matches);
> print_r($matches);
> 
> This currently makes two arrays for me, the source location from all
> img tags and a large part of the tag itself. But not the entire tag.
> 
> What i do is i match the img tag, find the src, get the image
> properties, and if the width is more than 500, i shrink it down and
> add width="X" and height="Y" properties to the image tag.
> 
> How can i match an image tag correctly so it does not cause any issues
> with how the user adds the image.
> 

<style>
#your_content_div img { max-width: 500px !important; }
</style>

OK, so it won't work with IE6. Screw them.

But if the height is set in the img tag it'll keep that, so the image 
could become distorted. So, you could also do something like:

#your_content_div img { visibility: none; }

Then run some Javascript routine onload to properly figure the 
dimensions of each image. Adjust the width down to 500px, if necessary, 
then the height by whatever percent difference between original width 
over new width:

var new_height = (original_width / 500) * original_height;

Then, whether you change the dimensions of the image or not, change the 
visibility of each to 'visible'.

So, um ... no PHP involved.

brian

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

--- End Message ---
--- Begin Message ---
I've done that on occasion, but do be careful what you are sending via
the GET.

It has a size limit for one (maybe 1k chars?) and it is trivial for
someone to modify.

I generally use GET when I think it's a page "setup" the user may wish
to bookmark (ie: page.php?orderby=name&descending=1&report=69 )

And POST for submitting data that I want to save. (ie: add a new user
and all their glory).

I have done a mixture, such as page.php?action=delete&id=5 

But you have to be careful. I guess I always have some kind of user
class and verify they have permissions to use the page and or delete
said record anyways (logging failed attempts of course).

> -----Original Message-----
> From: Ray [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, August 08, 2007 8:19 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] get and post together
> 
> Hi all,
> I've done something and I want to know if I should be ashamed :)
> 
> I've set up a form with method="POST" and target ="page.php?foo=bar"
> it works fine. $_POST[...] gives me the data I want and 
> $_GET['foo']=='bar'.
> I freely admit it's an ugly kludge, but is it "bad"?
> Ray
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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

On Aug 8, 2007, at 9:34 PM, Richard Lynch wrote:

On Wed, August 8, 2007 7:52 pm, jekillen wrote:
I have a question about including php files that are outside of
the web server document root. What permission does Apache
use to access files outside of the document root?
Here is the situation:
I want to store sensitive data such as login/pw data for
registered users. I also want to make all the web content
rwx for user nobody (FreeBSD) only. So no ftp access,
no mortal user access, etc. Is it possible to  do this in
this situation? Would the Parent Apache process use
its privileges to include a file of this type?
I have texts and other data about storing data out side
the document root,  but  none go into it in this detail?

Apache runs as the "User" setting in httpd.conf

If that "User" can rwx the files, then PHP can rwx the files.

If not, not.

It's that simple.

Thanks, so if I make the directory and file outside of the document
root owner noboby with rwx for owner only, that will work?
Jeff K

--- End Message ---
--- Begin Message ---
Steve Marquez wrote:
I know this code does not work, but I was curious if someone can take a look
and tell me what is wrong? Thank you so much.
Re-indent your code properly. If you do it will look like:

<?php
$pattern = ".html*|.php*";

if (is_dir("files/")) {
   if ($dh = opendir("files/")) {
       echo "<select name=\"file\" size=\"8\">";
       while (($file = readdir($dh)) !== false) {
           if (ereg($pattern, $file))
               if(strpos($file,'.')>0) {
                   $file_array = array($file);
                   sort ($file_array);

                   foreach($file_array as $key => $value) {
                       echo "<option value=\"$value\">".$value."</option>";
                   }
               }
           }
           echo "</select>";
           closedir($dh);
       }
   }
?>

You have a number of things you need to look at here. First, you don't have a final 
closing brace for your opening if() statement. Second, you're outputting the 
<option> tags INSIDE the while loop that reads the directory, so for every file 
you read your options list will get bigger. Well, it would, but you're also not using 
the right array append method; it should be:
                   $file_array[] = $file;

Next, you don't want to sort the array every time you add a file to it - just 
do it once when you're done.

Try this:
<?php
$pattern = ".html*|.php*";

if (is_dir("files/") && $dh = opendir("files/")) {
   echo '<select name="file" size="8">';
   while (($file = readdir($dh)) !== false) {
       if (!ereg($pattern, $file)) continue;
       if(strpos($file,'.')<1) continue;
       $file_array[] = $file;
   }

   sort ($file_array);
   foreach($file_array as $value) {
       echo '<option value="' . $value . '">' . $value . '</option>';
   }
   echo "</select>";
   closedir($dh);
}
?>

Syntax check is left as an exe3rcise for the student. =)

Regards,
Chad

--- End Message ---
--- Begin Message ---
I have received your document. The corrected document is attached.

++++ Attachment: No Virus found
++++ F-Secure AntiVirus - www.f-secure.com

Dangerous Attachment has been Removed.  The file "document.pif" has been 
removed because of a virus.  It was infected with the "W32/[EMAIL PROTECTED]" 
virus.  File quarantined as: "". 
http://www.fortinet.com/VirusEncyclopedia/search/encyclopediaSearch.do?method=quickSearchDirectly&virusName=W32%2FNetsky.P%40mm

--- End Message ---
--- Begin Message ---
ouch... hey it's work rite now... thanks a lot for your help Edward
and Stut, i really apprieciate it...

br///

On 8/9/07, Stut <[EMAIL PROTECTED]> wrote:
> Suprie wrote:
> >     function getDB()
> >     {
> >         return $this->$db;
> >     }
>
> There should not be a $ before db. It should be $this->db. That's why
> PHP is telling you the property is empty... because it is.
>
> -Stut
>
> --
> http://stut.net/
>


-- 
Jangan tanyakan apa yang Indonesia telah berikan pada mu
tapi bertanyalah apa yang telah engkau berikan kepada Indonesia

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GU/IT  d- s: a-- C++ UL P L++ E W++ N* o-- K-
w PS  Y-- PGP- t++ 5 X R++ tv  b+ DI D+ G e+ h* r- z?
 ------END GEEK CODE BLOCK------

--- End Message ---
--- Begin Message ---
Click me!

--- End Message ---

Reply via email to