Danack / PHP-to-Javascript

A tool for converting simple PHP objects/code to Javascript, so that code for manipulating objects can be used both server-side and client-side.
Other
104 stars 32 forks source link

multiline string #41

Closed ghost closed 11 years ago

ghost commented 11 years ago

multiline string is bad converted. on end of the line must be added "\"

ghost commented 11 years ago

please use PHP_EOL

function convertMultiLineString($string) {
    return str_replace(PHP_EOL, "\\".PHP_EOL, $string);
}

now its not work on my. its converted to

var multilineStr = "A
\B";
ghost commented 11 years ago

but in another file is parsed bad with PHP_EOL. maybe?

function convertMultiLineString($string) {
    $string = str_replace(PHP_EOL, "\\".PHP_EOL, $string);
    return str_replace("\n", "\\\n", $string);
}
Danack commented 11 years ago

I've changed it so that it tries to convert all three of \r\n, \r and \n to PHP_EOL.

That should mean that any line-ending would be converted to the current machines encoding. Can you let me know if that's now working for you?

ghost commented 11 years ago

no. its not work. maybe can you do this way ? 0fd05cd f51376ecf7

Danack commented 11 years ago

Can you post an example of it not working please?

ghost commented 11 years ago
    $html='<li id="ser_'.$id.'">
    <span><i class="icon-time"></i>'.$d.''.$cas.'</span>
    .....

is converted to this

    var html='<li id="ser_' + "" + id + "" + '">\\
\
\
        <span><i class="icon-time"></i>' + "" + d + "" + '' + "" + cas + "" + '</span>\\
\
\
......

and dont use 5.4 array syntax "$arr = []" please. Im working on 5.3

ghost commented 11 years ago

here you have file. maybe will be converted in you server same. http://uloz.to/x4vMeacE/schedule-phps

Danack commented 11 years ago

Thanks for the file. This almost certainly should be fixed now as it converted that file correctly.