john,

creating script snippits on the fly is generally not much use in an echo
statement because echos just stream to the clients browser - nothing in that
stream is actually ever going to be "executed"

The various solutions offered by other list members are particularly
relevant to the
creation of strings which will be written to a file.  In other words echoing
(to the browser) some html with a bit of PHP script buried in it (e.g. the
form tags) will do just that - send to the browser something that it doesn`t
understand, a browser can`t execute PHP script as it can say a piece of
javascript.

However, if you are writing a script which is intended to create yet another
script for later use, these techniques work.

 An example of a script that creates a script...



 <?php

 // the name of this script is suicidal.php

 $somefilename = "hello.php";

 $mystring = "<"."?"."php\n echo \"hello world\";\n"."?".">";

 $fhandle = fopen ($somefilename, "w");
 $writesuccess = fwrite ($fhandle, $mystring);
 fclose ($fhandle);

 ?>


 This will create a PHP script, a hello world script named hello.php.

 if we said (in the script) ...

 $somefilename = $PHP_SELF;

 then suicidal.php would  overwrite itself and become a hello world script.
 (permissions issues aside - you may not be able to overwrite a file that is
 actually executing at the time).


 For your problem, needing to create a form in the clients browser with
action=(the_same_script) you only need to so this ....

assuming a script file name of ...  add_to_cart.php


 echo "<form name=\"fred\" method=\"POST\" action=\"".$PHP_SELF."\">";

 If the browser user clicked on "show source" he or she would see this...

 <form name="fred" method="POST" action="add_to_cart.php">

 Is this what you want to do??

 As Maxim said, you don`t really have to concatenate so pedantically but it
 helps demonstrate what is happening.

 cheers CD


> ----- Original Message -----
> From: "John W. Holmes" <[EMAIL PROTECTED]>
> To: "'Philipp Bolliger'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Saturday, November 09, 2002 5:38 AM
> Subject: [PHP-WIN] RE: [PHP] How to echo the end marker '?>'
>
>
> > > subject's allready my question ! I want to echo something like :
> > "<form
> > > action = \",?php echo $PHP_SELF ?> \" >" so that the action becomes <?
> > > echo $PHP_SELF ?> !! But I can't figure out how to escape ?> so that
> > the
> > >   interpreter doesn't take it as the end of the script ! Any idea ?
> >
> > Maybe I don't understand... but,
> >
> > echo "<form action=\"<? echo \$PHP_SELF ?>\" >";
> >
> > ---John Holmes...
> >
> >
> >
> > --
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>


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

Reply via email to