0

I'm working on a wysiwyg and a section to insert source code like PHP/HTML/Perl/etc...

I use de PHP Geshi for highlight the code via jQuery.

Everything work well, I get my code well but I lost the char "+" in the returned code.

I think the problem comes from the fact that "$.post" interpret "+" such as adding a new parameter in the sending, I just be wrong.

I'm not even POST or GET is the right solution to get source code with lots of weird characters ... I'm interested in new idea ...

The jQuery Code :

$('#valider_code').click(function() { 
    // On selectionne le contenue du textarea

    var code = $("#code").val();
    code = addslashes(code);
    // On cache le div
    $('#input_code').hide();

    $.post('/get_geshi.php', { "code" : code, "langage" : langage }, function(data) {

    data = data.replace(/\n|\r|\r\n/g, '<br>');
       // On insert le code
    var embed = '<div id="code_source">'+ data +'</div>';
        if($.browser.msie) {
            var selection = editor.contentWindow.document.selection;
            var range = selection.createRange();
            range.pasteHTML(embed);

        }
        else {
        execCommand("inserthtml", embed);
        }
        langage = "";
        code = $("#code").val('');


    }); // Fin get
    return false; // prevent default
  });

get_geshi.php

<?php
require_once('geshi.php');

$source = stripslashes(urldecode($_POST["code"]));

$language = $_POST["langage"];

$geshi =& new GeSHi($source, $language);
echo $geshi->parse_code();

?>
UiUx
  • 967
  • 2
  • 14
  • 25
Pierre
  • 1
  • 1
  • Try to encode PHP returned text using : http://php.net/manual/fr/function.htmlentities.php – sdespont Feb 16 '13 at 09:27
  • People don't understand that `$.ajax` does the encoding itself. Can you drop any manipulation you are doing on `code`? Also, please post examples of actual and expected request and response – Alexander Feb 16 '13 at 10:25

1 Answers1

0

Y enter this line (Perl code) :

$line =~ /\s+(\S+)$/;

It's return this line :

$line =~ /\s (\S )$/;

The "+" drop.

Pierre
  • 1
  • 1