Php Code inside a link does not work

Last post 05-10-2008, 8:46 AM by alES. 9 replies.
Sort Posts: Previous Next
  •  02-26-2008, 3:56 PM 37370

    Php Code inside a link does not work

    Hello,
     
    For severals links on my website I need to include a snippet php code, but the editor translate the html code like this code is written in Normal mode.
     
    For example :
     
    If I set this :

         $editor->text = '<a target="_blank" href="<?php echo "test"; ?>"> myPhp link </a>'


    The editor return =>  '<a target="_blank" href="%3C?php%20echo%20"test";%20?%3E"> myPhp link </a>'
     
    How can I avoid these conversions ?
     
    Thanks in advance,
    alES
  •  02-27-2008, 3:13 AM 37384 in reply to 37370

    Re: Php Code inside a link does not work

    alES,
     
    It's not converted by Cute Editor. It's converted by PHP.
     
    Because the following code is wrong:
     
         <?php
                    $editor=new CuteEditor();
                    $editor->ID="Editor1";
                    $editor->Text='<a target="_blank" href="<?php echo "test"; ?>"> myPhp link </a>'
          ?>

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  02-29-2008, 2:51 PM 37478 in reply to 37384

    Re: Php Code inside a link does not work

    Adam, 
     
    Excuse me, my example is not enough relevant. In fact, I paste in this example the content of a variable filled by my database. So, the code is not converted by my PHP code but in the Cute PHP Code. I found on the the line 140 (include_CuteEditor) the conversion.
     
    Do you think this conversion is necessary for the next part of your code ? I already tried to suppress this conversion but javascript part do it also.
     
    How can I avoid this conversion to edit PHP code inside the links ?
     
    alES


  •  04-12-2008, 3:23 AM 39123 in reply to 37478

    Re: Php Code inside a link does not work

    Please Adam, do you have some info because I cannot use the editor where I have php inside my links. Thanks.
  •  04-12-2008, 10:39 AM 39132 in reply to 37478

    Re: Php Code inside a link does not work

    alES,
     
    >> I found on the the line 140 (include_CuteEditor) the conversion.
     
    No, Cute Editor doesn't do the convertion. You can check the include_CuteEditor.php file yourself.
     
    The following code is wrong:
     
         <?php
                    $editor=new CuteEditor();
                    $editor->ID="Editor1";
                    $editor->Text='<a target="_blank" href="<?php echo "test"; ?>"> myPhp link </a>'
          ?>
     
    It should be:
     
        <?php
                    $editor=new CuteEditor();
                    $editor->ID="Editor1";
                    $editor->Text='<a target="_blank" href="<?php echo "test"; ?>"> myPhp link </a>'
          ?>

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  04-12-2008, 1:10 PM 39140 in reply to 39132

    Re: Php Code inside a link does not work

    Hi Adam,
     
    It's a bit difficult to explain but I'm trying differently.
     
    First, I store in my database the following value :  '<a target="_blank" href="<?php echo "test"; ?>"> myPhp link </a>'
     
    Second, I retrieve my value in $var, then :
     
        $var contains '<a target="_blank" href="<?php echo "test"; ?>"> myPhp link </a>'
     
    After, I call the editor like that :
     
         <?php
                    $editor=new CuteEditor();
                    $editor->ID="Editor1";
                    $editor->Text=$var;
          ?>

    So, when the file is reading $var cannot be converted here.
     
    But, when I call the editor, it exists the following instruction on line 140 of the file  include_CuteEditor.php :
     
        return htmlspecialchars($s_Text);
     
    ...and if I don't make a mistake htmlspecialchars function convert every special characters like <?... in the url lines. The following example is given on php website :
     
    <?php
    $new 
    htmlspecialchars("<a href='test'>Test</a>"ENT_QUOTES);
    echo 
    $new
    // &lt;a href='test'&gt;Test&lt;/a&gt;
    ?>
     
    It's exactely the conversion I want to avoid.
     
    I already eliminate this conversion, but I guess it exists the same conversion in the javascript files.
     
    The goal to edit php snippet code in the html files allow to execute this code when I display this content on my web site. Of course, I don't want to execute this code in the editor. Before I used the KTML editor and no conversion was operated it's why I hope it will be possible to do the same with CuteEditor.
     
    I hope this new explanation will be better.
     
    Thanks in advance,
    AlES
  •  04-20-2008, 11:03 AM 39520 in reply to 39132

    Re: Php Code inside a link does not work

    Hi Adam, I tried to explain again just before is it a better explanation ? If yes (or enough) do you have an idea ? Thanks
  •  04-21-2008, 9:24 PM 39592 in reply to 39520

    Re: Php Code inside a link does not work

    well, I am just a developer using Cute Editor and PHP the first time. But try this:
    editor->Text='<a target="_blank" href="' .<?php echo "test"; ?> . '"> myPhp link </a>'
  •  04-22-2008, 3:44 PM 39669 in reply to 39592

    Re: Php Code inside a link does not work

    Thanks murli, unfortunately this syntax cannot be support by an html editor, because i need to write the href value in the url field, and it's not possible to write that.
     
    ADAM ! ! ! HELP ! ! ! ! Did you check the javascript files ?

  •  05-10-2008, 8:46 AM 40268 in reply to 39669

    Re: Php Code inside a link does not work

    Hi Adam,
     
    I cannot tell you "thanks" to solve my problem. I give here the solution because I'm pretty sure it can be very useful for some PHP programmers.
     
    First of all, I discover when the problem appears. On your demo website, I wrote the following strings in HTML mode :
     
    <a target="_blank"
    href="<?php echo getUrlRedirect('../../', 'http://www.test.co.uk/'); ?>">Test</a>
    <a href="<?php echo getUrlRedirect('../../', 'http://www.test.co.uk/'); ?>" target="_blank" >Test</a>
     
     Go in Normal Mode, then in HTML mode, you get that :
     
     <a target="_blank" href="%3C?php%20echo%20getUrlRedirect%28%27../../%27,%20%27http://www.scrapandstamp.co.uk/%27%29;%20?%3E">Test</a>
    <a href="&lt;?php echo getUrlRedirect('../../', 'http://www.scrapandstamp.co.uk/'); ?&gt;" target="_blank">Test</a>
     
     These two links are exactely the same, the only difference it's the carriage return for the first one (just after _blank") that give an href translation with an urlencode function, not for the second one.
     
    My solution. When I retrieve the resulting string from CuteEditor in $_POST['id'], I convert like that :
     
    str_replace(array('&lt;?','?&gt;'),array('<?','?>'),urldecode($_POST['id']))
     
    That's all, now I can edit php code inside links, but the number of tests and days to think about was a bit huge !
     
    Otherwise, CuteEditor is a fabulous HTML editor....I will upgrade my license.
     
    AlES
     

View as RSS news feed in XML