Re: [PHP] string as file

2007-08-10 Thread Stut

Robert Cummings wrote:

On Fri, 2007-08-10 at 16:28 +0100, Stut wrote:

Rick Pasotto wrote:

On Fri, Aug 10, 2007 at 02:19:29PM +0100, Stut wrote:

Rick Pasotto wrote:

On Thu, Aug 09, 2007 at 03:25:27PM -0500, Greg Donald wrote:

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

Explain.
One word responses really don't do any good.
Exactly *what* would be the argument to eval()?

RTFM, that's what it's there for.

I did. That's why I rejected the use of eval() before I posted the
message. eval() is totally unsuitable for what I want. Unless, that is,
you or Greg can explain how using eval() will get me what I want.

I think that neither you nor Greg understands what I'm looking for.

Instead of simply stating 'RTFM' perhaps *you* should RTFQuestion.

Your original post asked...

Can I someout include a string instead of a file?

That's exactly what eval does. As for what you would pass to it... PHP 
code maybe? Have you even tried it? The manual page for eval has several 
examples of how to use it, and the comments have even more.



Incidentally, eval is evil and potentially a giant security hole.
You'd be better off doing replacements with preg_match rather than
executing a string.

Agreed. That's another reason I had already rejected it. Although in
this case, since I would have full control of all the variables, it
would probably be ok.
Use regular expressions or straight string replacements - that's the 
best way to implement mail-merge type behaviour. Personally I used 
preg_replace with the 'e' modifier. For an example see, shockingly, the 
manual page for preg_replace.


Now go stick your head in a pig.


Spider-Pig, Spider-Pig, does whatever a Spider-Pig does...

:) I love Fridays!!


It's Friday? Gawdammit!

-Stut

--
http://stut.net/

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



Re: [PHP] string as file

2007-08-10 Thread Robert Cummings
On Fri, 2007-08-10 at 16:28 +0100, Stut wrote:
 Rick Pasotto wrote:
  On Fri, Aug 10, 2007 at 02:19:29PM +0100, Stut wrote:
  Rick Pasotto wrote:
  On Thu, Aug 09, 2007 at 03:25:27PM -0500, Greg Donald wrote:
  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()
  Explain.
  One word responses really don't do any good.
  Exactly *what* would be the argument to eval()?
  RTFM, that's what it's there for.
  
  I did. That's why I rejected the use of eval() before I posted the
  message. eval() is totally unsuitable for what I want. Unless, that is,
  you or Greg can explain how using eval() will get me what I want.
  
  I think that neither you nor Greg understands what I'm looking for.
  
  Instead of simply stating 'RTFM' perhaps *you* should RTFQuestion.
 
 Your original post asked...
 
 Can I someout include a string instead of a file?
 
 That's exactly what eval does. As for what you would pass to it... PHP 
 code maybe? Have you even tried it? The manual page for eval has several 
 examples of how to use it, and the comments have even more.
 
  Incidentally, eval is evil and potentially a giant security hole.
  You'd be better off doing replacements with preg_match rather than
  executing a string.
  
  Agreed. That's another reason I had already rejected it. Although in
  this case, since I would have full control of all the variables, it
  would probably be ok.
 
 Use regular expressions or straight string replacements - that's the 
 best way to implement mail-merge type behaviour. Personally I used 
 preg_replace with the 'e' modifier. For an example see, shockingly, the 
 manual page for preg_replace.
 
 Now go stick your head in a pig.

Spider-Pig, Spider-Pig, does whatever a Spider-Pig does...

:) I love Fridays!!

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

Leveraging the buying power of the masses!
...

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



Re: [PHP] string as file

2007-08-10 Thread Jim Lucas

Rick Pasotto wrote:

On Thu, Aug 09, 2007 at 02:39:51PM -0700, Jim Lucas wrote:

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

$string = 'Hi, my name is |FIRST_NAME| |LAST_NAME|.';

$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 ) {

$in = array_keys($row);

foreach ( $in AS $k = $v )
$in[$k] = '|'.$v.'|';

echo str_replace($in, $row, $string);

}

?



You have misunderstood. You are still putting the template in an
external file. I want it in the main file. I don't want to maintain
two different files.






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



Re: [PHP] string as file

2007-08-10 Thread Stut

Rick Pasotto wrote:

On Fri, Aug 10, 2007 at 02:19:29PM +0100, Stut wrote:

Rick Pasotto wrote:

On Thu, Aug 09, 2007 at 03:25:27PM -0500, Greg Donald wrote:

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

Explain.
One word responses really don't do any good.
Exactly *what* would be the argument to eval()?

RTFM, that's what it's there for.


I did. That's why I rejected the use of eval() before I posted the
message. eval() is totally unsuitable for what I want. Unless, that is,
you or Greg can explain how using eval() will get me what I want.

I think that neither you nor Greg understands what I'm looking for.

Instead of simply stating 'RTFM' perhaps *you* should RTFQuestion.


Your original post asked...

Can I someout include a string instead of a file?

That's exactly what eval does. As for what you would pass to it... PHP 
code maybe? Have you even tried it? The manual page for eval has several 
examples of how to use it, and the comments have even more.



Incidentally, eval is evil and potentially a giant security hole.
You'd be better off doing replacements with preg_match rather than
executing a string.


Agreed. That's another reason I had already rejected it. Although in
this case, since I would have full control of all the variables, it
would probably be ok.


Use regular expressions or straight string replacements - that's the 
best way to implement mail-merge type behaviour. Personally I used 
preg_replace with the 'e' modifier. For an example see, shockingly, the 
manual page for preg_replace.


Now go stick your head in a pig.

-Stut

--
http://stut.net/

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



Re: [PHP] string as file

2007-08-10 Thread Rick Pasotto
On Fri, Aug 10, 2007 at 02:19:29PM +0100, Stut wrote:
 Rick Pasotto wrote:
 On Thu, Aug 09, 2007 at 03:25:27PM -0500, Greg Donald wrote:
 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()
 Explain.
 One word responses really don't do any good.
 Exactly *what* would be the argument to eval()?

 RTFM, that's what it's there for.

I did. That's why I rejected the use of eval() before I posted the
message. eval() is totally unsuitable for what I want. Unless, that is,
you or Greg can explain how using eval() will get me what I want.

I think that neither you nor Greg understands what I'm looking for.

Instead of simply stating 'RTFM' perhaps *you* should RTFQuestion.

 Incidentally, eval is evil and potentially a giant security hole.
 You'd be better off doing replacements with preg_match rather than
 executing a string.

Agreed. That's another reason I had already rejected it. Although in
this case, since I would have full control of all the variables, it
would probably be ok.

-- 
Whatever crushes individuality is despotism, by whatever name it may be
 called. -- John Stuart Mill, 1859
Rick Pasotto[EMAIL PROTECTED]http://www.niof.net

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



Re: [PHP] string as file

2007-08-10 Thread Rick Pasotto
On Thu, Aug 09, 2007 at 02:39:51PM -0700, Jim Lucas wrote:
 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));
 ?

You have misunderstood. You are still putting the template in an
external file. I want it in the main file. I don't want to maintain
two different files.

-- 
It is always from a minority acting in ways different from what the
 majority would prescribe that the majority in the end learns to do
 better. -- Friedrich Hayek
Rick Pasotto[EMAIL PROTECTED]http://www.niof.net

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



Re: [PHP] string as file

2007-08-10 Thread Rick Pasotto
On Thu, Aug 09, 2007 at 03:25:27PM -0500, Greg Donald wrote:
 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()

Explain.

One word responses really don't do any good.

Exactly *what* would be the argument to eval()?

-- 
In vices, the very essence of crime -- that is, the design to injure the
 person or property of another -- is wanting. It is a maxim of law that
 there can be no crime without a criminal intent. -- Lysander Spooner
Rick Pasotto[EMAIL PROTECTED]http://www.niof.net

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



Re: [PHP] string as file

2007-08-10 Thread Stut

Rick Pasotto wrote:

On Thu, Aug 09, 2007 at 03:25:27PM -0500, Greg Donald wrote:

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


Explain.

One word responses really don't do any good.

Exactly *what* would be the argument to eval()?


RTFM, that's what it's there for.

Incidentally, eval is evil and potentially a giant security hole. You'd 
be better off doing replacements with preg_match rather than executing a 
string.


-Stut

--
http://stut.net/

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



[PHP] string as file

2007-08-09 Thread Rick Pasotto
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

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



Re: [PHP] string as file

2007-08-09 Thread Greg Donald
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/

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



Re: [PHP] string as file

2007-08-09 Thread Jim Lucas

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

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