The WYSISYG editor doesn't like PHP code

I click on the php icon, then paste my php code. However, when I save new posts it shows my php code as a mess. What am I doing wrong?

Are you speaking about the post editor on this forum?

Yes.

After clicking the PHP button do you see

 bbcode tags appear in the editor?

[ot]I've moved your topic to the Forum Support and Feedback section as it is more applicable to this question.[/ot]

Yes, I do. That is why I don’t understand why the code looks scrambled after I click the post button.

Can you link me to an example please @busboy; ?

If you take this post of yours, you’ll notice that you are using

 tags rather than 
```php
 tags. That could be the issue.

Search your editor and see if there is a function to “change TABS to SPACES”.

Does that mean that users on this website could be using different types of editors? That is really strange. I just click on the advanced button so that the PHP icon appears. Here is how it looks when I paste code in between those two tags:

			$sentAlerts++;						$alerts++;					$increaseAlerts = "UPDATE searches SET alerts = $alerts, lastAlert = '$longDate' WHERE sID = $sID";						mysql_query($increaseAlerts) OR die("<b>A fatal MySQL error occurred</b>.\
<br />Query: " . $increaseAlerts . "<br />\
Error: (" . mysql_errno() . ") " . mysql_error()); 											$updateLastMatch = "UPDATE users SET lastMatch = '$longDate' WHERE uID = '$uID'";						mysql_query($updateLastMatch) OR die("<b>A fatal MySQL error occurred</b>.\
<br />Query: " . $updateLastMatch . "<br />\
Error: (" . mysql_errno() . ") " . mysql_error()); 										if ($clicks > 0) {							$ctr = $clicks/$alerts;				$percent = round($ctr * 100);				$showPercent = "$percent%";						} else {							$percent = "0";				$showPercent = "-";			}

Removed formatting and simplified in next post…

Using this editor and the “Switch editor to WSIWYG Mode” THEN manually applying the PHP tags


    $sentAlerts++;
    $alerts++;
    $increaseAlerts    =
    "
        UPDATE    searches
        SET            alerts =    $alerts, lastAlert = '$longDate'
        WHERE        sID    =    $sID
    ";

    mysql_query( $increaseAlerts )
    OR
    die(
            "<b>A    fatal    MySQL    error    occurred</b>.\
<br />Query:    "
            .    $increaseAlerts
            .    "<br />\
Error:    ("
            .        mysql_errno()
            .    ") "
            .    mysql_error()
            );

    $updateLastMatch =
    "
        UPDATE users SET lastMatch = '$longDate'
        WHERE    uID    =    '$uID'
    ";

    mysql_query($updateLastMatch)
    OR
    die
    (
            "<b>A    fatal    MySQL    error    occurred</b>.\
<br/>Query: "
        .    $updateLastMatch
        .    "<br />\
Error:    ("
        .    mysql_errno()
        .    ") "
        .    mysql_error()
    );

    if ($clicks    >    0)
    {
        $ctr                    =    $clicks/$alerts;
        $percent            =    round( $ctr    *    100    );
        $showPercent    =    "$percent%";
    }
    else
    {
        $percent = "0";
        $showPercent = "-";
    }


Conclusion:
It is not necessary to use my editors “TABS to SPACES” option but must use the WYSIWYG option and then to use the PHP tags.


	if ($formContact != $_SESSION[contact]) {		$madeChanges  = "Yes";	$changedData .= "<li><h6>Contact From Other Users:</h6>$_SESSION[contact] changed to $formContact</li>";	}				if ($formSendMatches != $_SESSION[sendMatches]) {		$madeChanges  = "Yes";	$changedData .= "<li><h6>Receive Testimonial Match Emails:</h6>$_SESSION[sendMatches] changed to $formSendMatches</li>";	}	

  1. I clicked on the button to “Go Advanced”.
  2. Then I clicked on the button for “Switch editor to WSIWYG Mode”.
  3. Then I clicked the button on the menu bar for PHP code snipet.
  4. I copied some of my source code from CODA on my iMac
  5. Then I pasted it between the PHP tags
  6. Clicked save

The PHP code looks like a mess. What am I doing wrong?

Silly question, what’s your OS and what editor are you copying from? I’ve got the sneaking suspicion the problem lies somewhere between your browser and the editor…

“Reply with quote” usually shows you exactly what’s been posted, and there’s no carriage returns in your post – so I would assume that you’re either losing them during copy to the clipboard, or when pasting. If you’re using an editor that doesn’t preserve linefeeds. I’ve seen this when people use ‘textedit’ and on a handful of *nix editors. The Linux world in particular can be a nightmare given the variety of different clipboard formats applications recognize (or don’t).

Though really, my advice is forget the stupid editor – the forums are faster and more useful if you turn off the MEGABYTE of .js garbage anyways.

Q: if you type in the PHP bbcode tag by hand, and then post into the editor box your code – does it have line-feeds in the editor box? If it does NOT show up with linefeeds in the editor window, the problem is NOT these forums, it’s somewhere between your browser and your editor.

Testing…123



// Pasted directly from CODA on a Mac:

$pageWelcome .= "<ul class='star'>";
if ($_SESSION[sponsorPosts] > 0)  {
	$pageWelcome .= "<li><a href = 'aromatherapy/7/$sponsorID'>Read my personal experiences</a></li>";}

// Some code manually typed in:

$myTest = "Hello";

if ($myTest == "Hello") {
	$pageWelcome .= "<li><a href='https://www2.example.com/signup/custType.faces?sponsorid=$sponsorMemberNumber&enrollerid=$sponsorMemberNumber'>Signup with as a customer or distributor</a></li>";
}

It looks like it’s better for me to manually add the PHP tags. It still doesn’t preserve the same indenting that I used in CODA, but it certainly looks better than it did before.

Thanks.

Using this editor and the “Switch editor to WSIWYG Mode” THEN manually applying the PHP tags

My Conclusion was not precise - it is necessary to manually include the PHP tags

Conclusion:
It is not necessary to use my editors “TABS to SPACES” option but must use the WYSIWYG option and then to use the PHP tags.

Hi,

What I do is first use the tags around my PHP. Then I preview; usually it displays with the tabs/spaces I have in my code. I then manually change the tags to . Before coming to this process I tried:

  • Changing my php editor in Eclipse to use spaces not tabs… this did not help
  • Paste my code into a text editor (gedit) and ask it to Paste using no formatting… this did not help
  • Manually adding
    ```php
    tags from the start… this did not help

I think that the javascript that is used in the editor does not parse spaces,
\r, \r. When previewing it preserves and/or converts the code spaces, tabs ect. Then wrapping these converted spaces with the tag


```html
 ... that your want. Interestingly this does not happen if I have used Code Highlighting for PHP.

I do use Linux and Eclipse (A Java based editor), so I don't expect everything to work great on products that have mainly been designed with Windows and maybe Mac.

Regards,
Steve