How I can echo a code in php in dos

December 5, 2010 at 06:36:52
Specs: Windows 7
How I can echo a code in php like this......
<?php
$uploaddir = '';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
print "
";
 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
     print "succsesfull ";
     print "\n";
     print_r($_FILES);
 } else {
     print "oops:\n";
     print_r($_FILES);
 }
 print "
";
?>
######

when i'm trying to do ...
ech <?php >>C:\code.php

it said::
The filename, directory name, or volume label syntax is incorrect.
and i think the problem is in ( < ) .
so any ideas....

thxxxxxxxxxxxxxx


See More: How I can echo a code in php in dos

Report •


#1
December 5, 2010 at 08:54:53
If I understand correctly you want to use a batch script to generate a php script.

A few points:


These characters need to be escaped (the escape character is the caret "^").

<>|&^


echo <>|&^                     -- won't work
echo ^<^>^|^&^^                --will work 


If you are using a code block in the batch script market with parentheses (typically used with the for and if commands) then you will also need to escape:

)(

echo )(                   -- may exit a code block
echo ^)^(                  -- won't


If you happen to be using delayed expansion (i.e setlocal enabledelayedexpansion) then exclamation marks need to be escaped twice.

echo !                      -- if enabled you won't get the exclamation mark
echo ^^!                   -- escape twice and it will appear

I would also suggest using a dot after echo, instead of a space, so you can output leading spaces and the words "on" and "off"


echo.              Leading spaces
echo.on   [the word on]


Report •

#2
December 5, 2010 at 09:06:38
I forgot one last thing, it's not a bad idea to redirect before using echo. That way you won't get trailing spaces or conflicts when the last two characters are <space><[0-9]>.

>>C:\code.php echo.^<?php

Lastly since it's all static text you can also get away with a code block (as long as you escape correctly):


(
    echo.     Line 1^)
    echo. line 2 ^&
    echo.ect,ect
) >> "file.txt"


Report •

#3
December 6, 2010 at 07:26:17
thank you very very much.....i think that im in puzzle.....but i will try to understand your explain....thx a lot

Report •
Related Solutions


Ask Question