|
Posted by Jochem Maas on 10/02/83 11:28
Suresh Pandian wrote:
> hello friends,
>
> i have a query in writng the content of one file to another.
> i attempted it.
> it only writes the html codings.it could not write the php scripts inside the file.
Suresh - it helps if you desribe what you are trying to achieve _and_
why, this is because there maybe completely other ways to do what you want,
which people can only suggest if they have an idea of why you aer trying
to do something.
anyway it looks like you are trying to strip comments from your
php files ....
>
> i use the following code to accomplish my problem...
>
> ##############################################################
>
> if (!defined('T_ML_COMMENT')) {
> define('T_ML_COMMENT', T_COMMENT);
> } else {
> define('T_DOC_COMMENT', T_ML_COMMENT);
> }
> $source = file_get_contents('-.php');
funny filename.
> $tokens = token_get_all($source);
> foreach ($tokens as $token) {
> if (is_string($token)) {
> // simple 1-character token
> $ourFileName = "/home/itempla1/public_html/links/".$pwd.".php";
> $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
I have a sneaking suspicion that if you changed the above line to:
$ourFileHandle = fopen($ourFileName, 'a') or die("can't open file");
things will start to work as you expect them. (notice your currently
opening it as 'write only' which truncates the file to zero bytes)
also it seems a bit wasteful to keep opening/closing this file handle
everytime you want to write something. myabe you should consider
to open/close the file just once (outside the loop)
> echo $token;
> fwrite($ourFileHandle, $token);
> fclose($ourFileHandle);
> } else {
> // token array
> list($id, $text) = $token;
> switch ($id) {
> case T_COMMENT:
> case T_ML_COMMENT: // we've defined this
> case T_DOC_COMMENT: // and this
> // no action on comments
> break;
> default:
> // anything else -> output "as is"
> $ourFileName = "/home/itempla1/public_html/links/".$pwd.".php";
> $ourFileHandle = fopen($ourFileName, 'a') or die("can't open file");
> echo $text;
> fwrite($ourFileHandle, $text);
> fclose($ourFileHandle);
> break;
> }
> }
> }
>
> ?>
> ################################################################
>
>
>
> please give me some valuable tips to write the content of the php file to another newly created php file.
>
>
> Thanks,
>
> Suresh.P
>
>
>
> ---------------------------------
> Yahoo! India Matrimony: Find your partner online.
Navigation:
[Reply to this message]
|