Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echoing HTML with PHP causing syntax error due to quotes [closed]

I'm using knockout.js with PHP and I'm trying to make a GET request which then returns an HTML/knockout form. The reason for doing this is because the form will be used by others, and rather than copying/pasting a rather large chunk of code, it's simply less code just to make a request to my server which returns the HTML/knockout.

//code on another server to request form from my server
$.ajax({
      //request here
    })
</script>

<div id = "update_div">
        <!--form data goes here when received -->
</div>

Now, this is the code on my server. Where the issue lies is that since I have to echo using php and I'm returning text, I need to use either a single or double quote around the text I'm echoing. However, I'm using knockout.js and a knockout.js validation addon which requires both single and double quotes, essentially canceling out the quotes wrapping the echo.

For example,

 <?
    if($_GET['something']){
       echo '
         <tr>
            <td>Full Name</td>
            <td><span data-bind="validationOptions: { insertMessages: false}">
            <input type="text" data-bind="value: fullName, valueUpdate: 'afterkeydown'"/></span></td> 
            <td data-bind="validationMessage: fullName"></td>
        </tr>
       ';
     }
 ?>

The line that is specifically causing the problem is

<input type="text" data-bind="value: fullName, valueUpdate: 'afterkeydown'"/></span></td>

Which the error returned is

Parse error: syntax error, unexpected 'afterkeydown' (T_STRING)

When I echo I use single quotes because I want to return it as text, however, within that I need to use single and double quotes for different elements. IS there a way around this?

like image 679
user1104854 Avatar asked Jul 04 '26 23:07

user1104854


1 Answers

try this -

<?
    if($_GET['something']){
       echo '
         <tr>
            <td>Full Name</td>
            <td><span data-bind="validationOptions: { insertMessages: false}">
            <input type="text" data-bind="value: fullName, valueUpdate: \'afterkeydown\'"/></span></td> 
            <td data-bind="validationMessage: fullName"><center></center></td>
        </tr>
       ';
     }
 ?>
like image 76
Mohammad Adil Avatar answered Jul 07 '26 12:07

Mohammad Adil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!