Skip to main content
Participant
November 5, 2016
Answered

Dreamweaver destroying php-code

  • November 5, 2016
  • 3 replies
  • 1449 views

why does Dreamweaver change my code from this id="<?php echo "$id"; ?> to this id="<?php echo " $id "; ?> when I use automatic code formatting

    This topic has been closed for replies.
    Correct answer Nancy OShea

    Shouldn't that be

       id="<?php echo $id;?>"

    Nancy O.

    3 replies

    fraktalfabrik
    Participating Frequently
    January 8, 2017

    I have noticed more than once that DW 2017 (b9314) formatting ruins working PHP code.

    I've tried this repeatedly and it always does the same. Would like to know if this is happening for others (?)

    Just copying the below code into a PHP doc

    <?

    $self = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

    $self = str_replace('Entry_amp','Entry',$self);

    ?><!doctype html>

    and running EDIT->CODE->APPLY SOURCE FORMATTING turns it into something that is logically completely different:

    <?= $self ?>

    _SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'PHP_SELF' ];

    $self = str_replace( 'Entry_amp', 'Entry', $self );

    ?>

    <!doctype html>


    Further down it also destroys any AMP code that is "space sensitive". That, I can live with, it's almost to be expected (albeit of course it'd be nice if DW was smart enough to avoid that).
    But doing the above change to the code is a real pain. How can "formatting" of the code change the actual order of the characters?

    BenPleysier
    Community Expert
    Community Expert
    January 8, 2017

    Upgrade to CC2017.0.1

    Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
    fraktalfabrik
    Participating Frequently
    January 10, 2017

    After the update I can no longer repeat the above outcome. Progress But it's still buggy. Example:

    (note: code starts off with 2 empty line-breaks and 2 spaces. Can't really see this here. If I delete the whitespace it works)

        <?

      if(!isset($state)){

       $state = STATE;

      }

    <

    ?

    if ( !isset( $state ) ) {

      $state = STATE;

    }

    It breaks up the  a <? tag and adds a line break.

    Even more weird and annoying is that it also turns

    <? } ?>

    into

    <

    ?

    }

    ?>


    Am I missing something here? This seems really strange behavior. I couldn't think of a single example where breaking up the tag is "right" thing to do. The opposite.

    Rob Hecker2
    Legend
    November 5, 2016

    Please specify the version of DW that is doing this.

    I've never seen DW do this. I have not upgraded to DW 2017 yet.

    Anyway, Nancy is right that the quotes in the PHP code serve no purpose and removing them may fix the problem.

    Nancy OShea
    Community Expert
    Nancy OSheaCommunity ExpertCorrect answer
    Community Expert
    November 5, 2016

    Shouldn't that be

       id="<?php echo $id;?>"

    Nancy O.

    Nancy O'Shea— Product User & Community Expert