I want to do a multiline search and delete with sed, deleting strings starting with /* and endding with *\ (removing multiline comments). After that I will pipe that into other seds to remove inline comments, than I will remove all new lines, then than replace all occurences of “<?php” with "<?php " (put spaces after <?php), and than delete double spaces. However, I can’t figure out the step 1. Anyone know how to do it.
Note: I am trying to get 1 long line php file, if any easier way to do this, I would appreciate your guideness.
I’m sure there’s an interesting explanation behind this exercise; care to
share?
Can it be done? Sure, I’m sure it can, but is it worth the risk of
introducing bugs in code needlessly? Doubt it.
Good luck.
On 12/17/2010 09:06 PM, yasar11732 wrote:
>
> Hi,
>
> I want to do a multiline search and delete with sed, deleting strings
> starting with /* and endding with *\ (removing multiline comments).
> After that I will pipe that into other seds to remove inline comments,
> than I will remove all new lines, then than replace all occurences of
> “<?php” with "<?php " (put spaces after <?php), and than delete double
> spaces. However, I can’t figure out the step 1. Anyone know how to do
> it.
>
> Note: I am trying to get 1 long line php file, if any easier way to do
> this, I would appreciate your guideness.
>
> Thanks in advance.
>
> Yaşar Arabacı.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
Well, I am doing this just for fun really, what I am to do after completing this step is, I ll create a for loop that,recursively minimalizing all php files in a given directory (I managed to get working copy of original file with one third space consuming for now), and instead of saving the output files to my computer, it will save output to remote server via ftp protocol, so that while keeping my human readible source files, my web server will contain only less space consuming files.
Edit: It is can be seen as kind of compressed file transfer of php files
for d in $(find -name \*.php);do
> cp $d $d.backup
> php -w $d.backup > $d
> rm $d.backup
> done
This code to remove comments and other unnecessary whitespaces. It seems like it worked so far. But if you want to use this code, use at your own risk. I don’t guarante that it would work as intended. I recommend backing for files before running this, and change your working directory to where you want to change php, keep in mind that his wil change files recursively
This doesn’t only remove comments but also strips whitespaces (new lines). If you just want to remove comments while leaving the scripts human readable, you should rather use the PHP tokenizer like in the function on that page: PHP: php_strip_whitespace - Manual