php-general Digest 10 Apr 2006 03:30:11 -0000 Issue 4063

Topics (messages 233622 through 233648):

Re: looking for shopping cart
        233622 by: Jochem Maas
        233626 by: tedd
        233627 by: tedd
        233633 by: Ryan A
        233634 by: Ryan A

Re: Date problems
        233623 by: Rasmus Lerdorf

Re: Completing forms offline with PHP/MySQL
        233624 by: Rory Browne

Re: how to kill session id without closing the window?
        233625 by: afan.afan.net

Re: Problems with Arrays and print and echo
        233628 by: Michael Felt

Re: Ajax please....
        233629 by: Michael Felt
        233631 by: tedd
        233632 by: Ryan A

function by reference
        233630 by: tedd
        233640 by: Robert Cummings

stripping enclosed text from PHP code
        233635 by: Winfried Meining
        233638 by: Satyam

php with ajax - uploading pictures
        233636 by: Merlin

Re: how to run 'periodic'
        233637 by: Frank Arensmeier

DDE + PHP
        233639 by: C.F. Scheidecker Antunes
        233641 by: tedd

Implied permissions
        233642 by: SLaVKa

Var within a var
        233643 by: bob pilly
        233647 by: Kevin Waterson

Variable within a Variable
        233644 by: bob pilly
        233645 by: Chris
        233646 by: Paul Novitski

How to use check box in CakePHP?
        233648 by: Pham Huu Le Quoc Phuc

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 ---
Ryan A wrote:
<CLIP>

[EMAIL PROTECTED] wrote:

Hi,

Why donot u people visit www.indialovesu.com and see the shop cart

which is

much -2 powerful than oscommerce.
U can reach to the design company at www.bsdinfotech.com


this mailing list is not a forum for advertising your companies'
products or services. probably half the members of this list work for
web development related companies; should we all send you our marketing
pitch?

-- </CLIP>You forgot to mention that the site (and domain name) also sucks
and the cart looks crappy,Thanks for sending us that link to bsdinfotech.com
coz now we know if ever we wantquality oursourcing to NEVER visit that site.

OH NO ... I didn't forget. I had a whole swathe of abuse ready for this guy
about his language /cultural skills and the dodgy design-by-template 
1999-dreamweaver
HTML crap (view source made me laugh anyway, especially when considered in the
light of point 2 on this page:

        http://www.bsdinfotech.com/doit.htm)

but then I thought better of it, heck the sun is shining today :-)

<SUB-Clip>should we all send you our marketing
pitch?
</SUB-Clip>Maybe we should _all_ send the spammer our marketing
pitches.....offlist :-)And yes, I do consider what he did SPAM.-Ryan

today I have someone trying to takeover my main webserver for use in a botnet,
SPAM is the least of my worries ;-)



--- End Message ---
--- Begin Message ---
At 4:03 PM +0200 4/9/06, Jochem Maas wrote:
[EMAIL PROTECTED] wrote:
Hi,

Why donot u people visit www.indialovesu.com and see the shop cart which is
much -2 powerful than oscommerce.
U can reach to the design company at www.bsdinfotech.com

this mailing list is not a forum for advertising your companies'
products or services. probably half the members of this list work for
web development related companies; should we all send you our marketing
pitch?

Well... if we did advertise, we would do a better job of it.

And, most of us have written a better shopping cart as well.

tedd
--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
At 11:36 PM -0400 4/8/06, Lisa A wrote:
I need a shopping cart for a website that once I install and set up, my
client can easily add merchandise to it.  They use Paypal.  It has to be
very easy for them to upload images and products, prices, etc.
If anyone knows of something, please let me know.
I host my own websites, so not interested in paying a monthly fee.
thanks,
Lisa

Lisa:

There are all sorts of shopping carts including PayPal -- you may want to look into that.

I have written forms for clients such that they can upload their products, image, price, product ID, and such and data is automatically posted to their MySQL dB, and from there, is available to their on-line catalog and from there, the products are just a click away from PayPal and PayPal's shopping cart. It's neat, simple, and works. No money other than your time to set it up.

<shameless plug>
If you want a more traditional shopping cart, you might look into Shop Script (I'm a distributor). I've installed and set-up a few of those. They cost, but are set up for an easy admin for civilians. If interested, contact me privately.
</shameless plug>

tedd
--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
Lisa,


--------------

<shameless plug>
If you want a more traditional shopping cart, you might look into
Shop Script (I'm a distributor). I've installed and set-up a few of
those. They cost, but are set up for an easy admin for civilians. If
interested, contact me privately.
</shameless plug>

-----------


Another thing to consider is that commercial programs often tend to have
better support
too incase things go wrong or you want modifications/added features.
Don't get me wrong, there are _many_ free programs that are supported very
well but they
are supported mostly by a community and if you want modifications you would
either have to
pay for it or wait a long time, if you dont know how to go in and do it
yourself of course.
The free system thinks more of how a modification would help the whole
community of users
rather than the single person who has a specific need (OSC as an example,
not that I am
bashing OSC...I installed it for more than one client myself.)

HTH.

Cheers,
Ryan

--- End Message ---
--- Begin Message ---
Hey,

--------------

OH NO ... I didn't forget. I had a whole swathe of abuse ready for this
guy
about his language /cultural skills and the dodgy design-by-template
1999-dreamweaver
HTML crap (view source made me laugh anyway, especially when considered
in the
light of point 2 on this page:

        http://www.bsdinfotech.com/doit.htm)-----------------

Hehehe someone certainly was hitting the thesaurus for point two:

" 2. Eradicating Existing Flaws. "



---------------

but then I thought better of it, heck the sun is shining today
:-)------------Lucky son of...oops, sorry, sometimes cant control the little
green monster in me :-DJ/K of course.------------ today I have someone
trying to takeover my main webserver for use in a botnet,
SPAM is the least of my worries ;-)------------------Sounds bad, best of
luck m8.Cheers,Ryan

--- End Message ---
--- Begin Message ---
Satyam wrote:
Timestamps are stored as seconds from a certain date. The base date differ depending on the platform, Windows use 1/1/1980 the rest 1/1/1970, but still seconds. 7 days are 7*24*60*60. Just add that much to a timestamp. It helps having a constant such as:

define ('DAY_IN_SECONDS',86400);

The problem with doing it this way is that it won't take leap seconds, leap years and daylight savings into account, so on any of these edge cases it will appear to be broken. That's why strtotime("+7 days") is the correct way to do this.

-Rasmus

--- End Message ---
--- Begin Message ---
I haven't thought about this much, but I'd probably create an onSubmit
handler, that would hide the form in an iframe, and create a new one. I
would then when they are online, submit all the forms.

This would require the user to keep the browser window open and at the same
page. Alternatively you could have the user allow the script to write files
to the local hard disk, and store the form data there. Making a .hta file
would probably be the easiest way to do this on windows.

On 4/7/06, Miles Thompson <[EMAIL PROTECTED]> wrote:
>
> At 01:06 PM 4/7/2006, Kevin Davies - Bonhurst Consulting wrote:
>
> >Hi,
> >
> >Apologies if this is the wrong place for this question, but I'm sure
> there
> >are some experts out there who might be able to point me in the right
> >direction... :)
> >
> >I'm doing some work at the moment where remote teams can submit reports
> >through to our database when connected over the internet to our server.
> >However, I've been asked to look in the possibility of the teams
> completing
> >the form offline, and uploading when they have access to a connection.
> >
> >It looks like I might be able offer something like Microsoft InfoPath
> forms
> >(better recommendations?) to generate an XML file, and then use a PHP
> file
> >to upload the file into the database. Additionally, I could also do with
> >this process uploading a number of other files (e.g. images, text files)
> to
> >the server.
> >
> >Does anyone have any experience in this area, and would be able to
> recommend
> >a solution?
> >
> >Thanks in advance for your help...
> >
> >Kevin
>
>
> PHP-GTK+
> GTK+ front end, laid out using wGlade (which creates an XML-like file with
> a .glade extension), and of course, PHP for all of your logic.
>
> Works
>
> Miles
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.1.385 / Virus Database: 268.3.5/303 - Release Date: 4/6/2006
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Yup! That works perfect!

Thanks Tedd

:)


-afan



> At 9:19 PM +0200 4/6/06, [EMAIL PROTECTED] wrote:
>>Hi to all,
>>
>>session_start();
>>$_SESSION['sessid'] = session_id;
>>
>>echo $_SESSION['sessid']; will show e.g. 699e506bd42ea402985dce24a0ef9
>>
>>After:
>>
>>unset($_SESSION['sessid']);
>>
>>$_SESSION['sessid'] = session_id();
>>
>>I'm getting the same SID again.
>>
>>I tried with session_unregister() and session_destroy() but same result.
>>
>>How can I create new, other sesssion id (after I, for example, click on
>>'Log Out' button) without closing window?
>>
>>Thanks for any help.
>
>
> Look up:
>
> http://www.weberdev.com/session_regenerate_id
>
> HTH's
>
> tedd
>
>
> --
> --------------------------------------------------------------------------------
> http://sperling.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
John Wells wrote:
echo "$this->name[5]\n";
echo "$this->ID[5]\n";
$a1 = $this->name;
$a2 = $this->ID;
echo "\n$a1[5] $a2[5]\n";


use curly brackets to help PHP understand what you're after:

echo "{$this->name[5]}\n";

When you're in a string like this, PHP has a hard time knowing when
you're wanting to access a variable, and when you're simply trying to
output text.  Using curly brackets clears it up.

HTH,
John W
Thanks.

--- End Message ---
--- Begin Message ---
tedd wrote:
Ryan:

Carlin Bingham / Tedd:
-----------------------
Yes, but then I would have to reload the whole page just to tell the person that the account username was already taken...thats how its "traditionally" done...but I want to try doing it without reloading the whole page...hence Asynchronous JavaScript And XML (AJAX) although the XML part at the end is
not really too accurate because from what I see you can (and i have) use
AJAX without any XML...in my case it would be AJAH or AJAT (H=HTML, T=TEXT)
:-p


Okay, you don't need to stick your tongue out -- I know what ajax is.

Please review:

http://www.xn--ovg.com/ajax

Is that what you want? If so, contact me privately and I'll provide you with the code. It's pretty simple really.

tedd
And I thought Ajax was a Dutch Football (soccer) team. :P

--- End Message ---
--- Begin Message ---
At 8:13 PM +0200 4/9/06, Michael Felt wrote:
And I thought Ajax was a Dutch Football (soccer) team. :P

It isn't??

tedd
--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
>  And I thought Ajax was a Dutch Football (soccer) team. :P


It is....and a very good dish washing detergent too (and yes, I am a
bachelor :-D )


Cheers,
Ryan

--- End Message ---
--- Begin Message ---
Hi gang:

Not that I have an immediate need for this, but in other languages one can access a function by reference (in other words, it's address -- such as call(function address) ).

In php, one can pass a variable by reference by simply using the ampersand, such a &$a.

Is there a similar way to reference a function?

Rob, was kind enough to post the following code, but I was looking for something where I could store the function's address in a variable. Something like:

$a = &f_a();

And then, where I could use call_user_func($a); (or something similar) and the function would do it's thing -- anything like that?

Thanks

tedd

--- Rob's suggestion follows.

Like the following?

<?php

function f_a()
{
    echo 'a';
}

function f_b()
{
    echo 'b';
}

function f_c()
{
    echo 'c';
}

$map = array
(
    'a' => 'f_a',
    'b' => 'f_b',
    'c' => 'f_c',
);

$map['a']();
$map['b']();
$map['c']();

?>


--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
On Sun, 2006-04-09 at 14:17, tedd wrote:
> Hi gang:
> 
> Not that I have an immediate need for this, but in other languages 
> one can access a function by reference (in other words, it's address 
> -- such as call(function address) ).
> 
> In php, one can pass a variable by reference by simply using the 
> ampersand, such a &$a.
> 
> Is there a similar way to reference a function?
> 
> Rob, was kind enough to post the following code, but I was looking 
> for something where I could store the function's address in a 
> variable. Something like:
> 
> $a = &f_a();
> 
> And then, where I could use call_user_func($a); (or something 
> similar) and the function would do it's thing -- anything like that?

It's the same thing for the most part...

<?php

$a = 'f_a';
call_user_func( $a, $p1, $p2, $p3 )

?>

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

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

I am writing on a script that parses a PHP script and finds all function calls 
to check, if these functions exist. To do this, I needed a function that would 
strip out all text, which is enclosed in apostrophes or quotation marks. This 
is somewhat tricky, as the script needs to be aware of what really is an 
enclosed text and what is PHP code. Apostrophes in quotation mark enclosed text 
should be ignored and quotation marks in apostrophe enclosed text should be 
ignored, as well. Similarly, escaped apostrophes in apostrophe enclosed text 
and escaped quotation marks in quotation mark enclosed text should be ignored. 

The following function uses preg_match to do this job. 

<?

function stripstrings($text) {
        while (preg_match("/^(.*)(?<!\\\)('|\")(.*)$/", $text, $matches)) {

                $front = $matches[1];
                $lim = $matches[2];
                $tail = $matches[3];

                while (preg_match("/^(.*)(?<!\\\)('|\")(.*)$/", $front, 
$matches)) {
                        $front = $matches[1];
                        $tail = $matches[3] . $lim . $tail;
                        $lim = $matches[2];
                }

                if (!preg_match("/^(.*)(?<!\\\)$lim(.*)$/", $tail, $matches))
                        break;

                $string = $matches[1];
                $tail = $matches[2];
                while (preg_match("/^(.*)(?<!\\\)$lim(.*)$/", $string, 
$matches)) {
                        $string = $matches[1];
                        $tail = $matches[2] . $lim . $tail;
                }

                $text = $front . $tail;
        }

        return($text);
}

?>

I noticed that this function is very slow, in particular because 

preg_match("/^(.*)some_string(.*)$/", $text, $matches);

always seems to find the *last* occurrence of some_string and not the *first* 
(I would need the first). There is certainly a way to write another version 
where one looks at every single character when going through $text, but this 
would make the code much more complex.

I wonder, if there is a faster *and* simple way to do the same thing. 

Is there btw a script freely available, which can parse PHP code and check for 
errors ?

Any help is highly appreciated.

Winfried

--- End Message ---
--- Begin Message ---
http://www.phpcompiler.org/

Satyam

----- Original Message ----- From: "Winfried Meining" <[EMAIL PROTECTED]>
To: <php-general@lists.php.net>
Sent: Sunday, April 09, 2006 10:20 PM
Subject: [PHP] stripping enclosed text from PHP code



Hi,

I am writing on a script that parses a PHP script and finds all function calls to check, if these functions exist. To do this, I needed a function that would strip out all text, which is enclosed in apostrophes or quotation marks. This
is somewhat tricky, as the script needs to be aware of what really is an
enclosed text and what is PHP code. Apostrophes in quotation mark enclosed text should be ignored and quotation marks in apostrophe enclosed text should be ignored, as well. Similarly, escaped apostrophes in apostrophe enclosed text and escaped quotation marks in quotation mark enclosed text should be ignored.

The following function uses preg_match to do this job.

<?

function stripstrings($text) {
while (preg_match("/^(.*)(?<!\\\)('|\")(.*)$/", $text, $matches)) {

$front = $matches[1];
$lim = $matches[2];
$tail = $matches[3];

while (preg_match("/^(.*)(?<!\\\)('|\")(.*)$/", $front, $matches)) {
$front = $matches[1];
$tail = $matches[3] . $lim . $tail;
$lim = $matches[2];
}

if (!preg_match("/^(.*)(?<!\\\)$lim(.*)$/", $tail, $matches))
break;

$string = $matches[1];
$tail = $matches[2];
while (preg_match("/^(.*)(?<!\\\)$lim(.*)$/", $string, $matches)) {
$string = $matches[1];
$tail = $matches[2] . $lim . $tail;
}

$text = $front . $tail;
}

return($text);
}

?>

I noticed that this function is very slow, in particular because

preg_match("/^(.*)some_string(.*)$/", $text, $matches);

always seems to find the *last* occurrence of some_string and not the *first* (I would need the first). There is certainly a way to write another version where one looks at every single character when going through $text, but this
would make the code much more complex.

I wonder, if there is a faster *and* simple way to do the same thing.

Is there btw a script freely available, which can parse PHP code and check for
errors ?

Any help is highly appreciated.

Winfried

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




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

I am searching for a good upload framework that works with PHP and AJAX to provide an upload interface that uploads one picture instantly, shows the thumbnail and displays another upload formfield to select the next picture for upload.

Is there something like this, or similar around?

Thank you for any hint,

Merlin

--- End Message ---
--- Begin Message ---
Thank you Joe for your input. I will take a look at crond.

/frank
7 apr 2006 kl. 20.06 skrev Joe Wollard:

Frank,

It sounds like you need to run this as a job through crond. I'm not sure what the OSX version is (maybe they have a port of crond?) but you could set that up to execute the specific code, as root, whenever you want. As far as I can think, and maybe Chris Shifflet can confirm/deny this, you shouldn't be running into any additional security issues by executing the script as root - As long as it's running through the CLI version of PHP. Just make
sure it's only executable by root and then root should be the only one
allowed to create that mammoth ;-)

- Joe

On 4/6/06, Frank Arensmeier <[EMAIL PROTECTED]> wrote:

Hi.

I have written a script which outputs a rather large ZIP file ( 200
MB ) by collecting a large amount of PDF files and html pages. When
the script is done, the available amount of free memory has decreased
by about 20 - 30%. Running 'periodic' on my machine ( Apple Xserve G5
with Mac OS 10.4 server) restores the available memory to a more
proper size.

The question is: how can I execute 'periodic daily|weekly|monthly'
from my script? Is this possible at all? I know that 'periodic' needs
root. And all PHP code is executed as www user which doesn't have
root privileges. Would I compromise my servers security when granting
root privileges to a script that executes 'periodic' (which could be
called from the script that outputs the ZIP archive)?

thanks
/frank

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



--- End Message ---
--- Begin Message ---
Hello,

I have an Excel spreadsheet that is automatically updated with quotes. I am doing a project for my BS and I need to grab the information from this spreadsheet and populate a MySQL database. Any ideas on how to accomplish that with PHP? The spreadsheet uses a DDE feed to fetch information from a third party service and needs to be opened.

I understand that I can do that with Java as well but if there is a way with PHP I prefer.

Thanks,

C.F.

--- End Message ---
--- Begin Message ---
At 4:59 PM -0600 4/9/06, C.F. Scheidecker Antunes wrote:
Hello,

I have an Excel spreadsheet that is automatically updated with quotes. I am doing a project for my BS and I need to grab the information from this spreadsheet and populate a MySQL database. Any ideas on how to accomplish that with PHP? The spreadsheet uses a DDE feed to fetch information from a third party service and needs to be opened.

I understand that I can do that with Java as well but if there is a way with PHP I prefer.

Thanks,

C.F.

Yep, you can upload an Excel spreadsheet and populate MySQL via php.

These links might give you a start.

http://www.weberdev.com/get_example-3591.html

http://www.weberdev.com/get_example-1270.html

As for DDE and third party service, I haven't a clue.

tedd
--
--------------------------------------------------------------------------------
http://sperling.com

--- End Message ---
--- Begin Message ---
Hey guys... implementing a permission system and just wanted some advice.

If i have permission A
which has implied permissions B and C

How do the permissions relate to each other, for eg if I select permission A to true, that implies that permission B and C must be set to true, but then if I set B to false or C to false, or both does that affect permission A?

Assuming that B, and C dont have implied rights you should be able to turn both of them off while leaving A on, but then that breaks the rule for A having implied permissions B and C.

Any help appreciated.

--- End Message ---
--- Begin Message ---
Hi All
 
 Im trying to store a document template in mysql that has php var names within 
it and then find it in the datebase and print it out with the var names 
replaced with the var values.
 
 e.g i have this stored
 
 Dear $title $name
 we would like to......
 
 I declare the vars $title and $name
 
 $title = 'Mr';
 $name = 'Test';
 //retrieve the stored template
 $query = "select template from letters";
 $result = mysqli_query($dblink,$query);
 if($row = mysqli_fetch_array($result)){
     print $row['template'];
 }
 
 i would expect that to print:
 
 Dear Mr Test
 we would like to......
 
 but it doesnt it prints out
 
 Dear $title $name
  we would like to......
 
 can someone point out where i am going wrong?
 
 Thanks for any help in advance!
 
 Cheers
 
 Bob
 
                
---------------------------------
Yahoo! Photos – NEW, now offering a quality print service from just 8p a photo.

--- End Message ---
--- Begin Message ---
This one time, at band camp, bob pilly <[EMAIL PROTECTED]> wrote:

> Hi All
>  
>  Im trying to store a document template in mysql that has php var names 
> within it and then find it in the datebase and print it out with the var 
> names replaced with the var values.

eval()

Kevin

-- 
"Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote."

--- End Message ---
--- Begin Message ---
  Hi All
  
  Im trying to store a document template in mysql that has php var names within 
it and then find it in the datebase and print it out with the var names 
replaced with the var values.
  
  e.g i have this stored
  
  Dear $title $name
  we would like to......
  
  I declare the vars $title and $name
  
  $title = 'Mr';
  $name = 'Test';
  //retrieve the stored template
  $query = "select template from letters";
  $result = mysqli_query($dblink,$query);
  if($row = mysqli_fetch_array($result)){
      print $row['template'];
  }
  
  i would expect that to print:
  
  Dear Mr Test
  we would like to......
  
  but it doesnt it prints out
  
  Dear $title $name
   we would like to......
  
  can someone point out where i am going wrong? Is this actually possible and 
if so im picking ive go the syntax wrong?
  
  Thanks for any help in advance!
  
  Cheers
  
  Bob
                
---------------------------------
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre.

--- End Message ---
--- Begin Message ---
bob pilly wrote:
  Hi All
Im trying to store a document template in mysql that has php var names within it and then find it in the datebase and print it out with the var names replaced with the var values. e.g i have this stored Dear $title $name
  we would like to......
I declare the vars $title and $name $title = 'Mr';
  $name = 'Test';
  //retrieve the stored template
  $query = "select template from letters";
  $result = mysqli_query($dblink,$query);
  if($row = mysqli_fetch_array($result)){
      print $row['template'];
  }
i would expect that to print: Dear Mr Test
  we would like to......
but it doesnt it prints out Dear $title $name
   we would like to......

If you don't get an immediate response you don't need to repost your question.

The data stored in the database is $title, $name, not the filled in variables. When php prints it out (in this case), it's printing it out exactly how it came out of the database. No variable substitutions etc take place unless you tell them to.

I'd suggest using htmlentities / htmlspecialchars to help make sure your data won't cause issues like XSS.

You could do:

print str_replace(array('$title', '$name'), array($title, $name), htmlentities($row['template']));

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

--- End Message ---
--- Begin Message ---
At 06:54 PM 4/9/2006, bob pilly wrote:
Im trying to store a document template in mysql that has php var names within it and then find it in the datebase and print it out with the var names replaced with the var values.


At 04:05 PM 4/7/2006, Paul Novitski wrote:
At 02:41 PM 4/7/2006, David Clough wrote:
I have to parse the string 'Hello $foo' as it comes from the
database: I don't get to construct it.

I did hold out more hope for the eval function, but it seems to me that
this is for PHP code in a database, not to evaluate variables.


David, please try the eval() route: it will do what you want. You say, "this is for PHP code in a database, not to evaluate variables," but evaluating variables is absolutely part of PHP code processing! Eval() will operate on "$x = 4;" just as easily as on "Hello $foo."

You should not use eval() frivolously because it presents a potential vulnerability in your code. You may wish to ensure that the database text it operates on is first cleansed of any other PHP syntax -- similarly to the way we should all ensure that any incoming data is clean before we process it and incorporate it into our scripts.

Here's an example of variaible evaluation:
_______________________

$bar = "cat";
$foo = "Hello \$bar.";

echo $foo;
RESULT: Hello $bar.

By escaping the $, I have made it a literal character in the text, the same as if I'd read "Hello $bar" from a database.
_______________________

eval("echo \"$foo\";");
RESULT: Hello cat.

This is equivalent to scripting:
        echo "$foo";
I'm using eval() to execute the echo command and interpret the PHP variable $foo.
_______________________

eval("\$dog = \$bar;");
echo "dog = " . $dog;

RESULT: dog = cat

Here I'm using eval() to set one PHP variable equal to another.
_______________________

You can't simply write:
        eval("\$bar;");
or
        $x = eval($foo);

because everything inside the eval() parentheses needs to be a complete PHP statement. The eval() function itself doesn't return the value of an evaluated expression. To capture the value of an expression, you must evaluate a complete statement that sets a variable equal to the expression as above.
_______________________

Clear as mud?

Regards,
Paul

--- End Message ---
--- Begin Message ---
Hi everybody!
I want to use a checkbox in Add, Edit form with CakePHP.
How to do? Please help me!



--- End Message ---

Reply via email to