• Resolved Glennf

    (@glennf)


    <?php
    if( aicp_can_see_ads() ) {
    // Shows the ad
    echo ”;
    }
    ?>

    I am putting code like the following (see below) inside the echo ”; but my code contains single quotes which conflict with the echo statement because the first single quote in my code complete the echo command.

    <script>
    document.write(‘<‘ + ‘h3 style=”text-align: center;”><‘ + ‘span style=”color: #a34040;”>’ + ‘More Gardening Ideas & Resources</span><‘ + ‘/h3>’);
    </script>

    What can I do to get around this?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author iSaumya

    (@isaumya)

    You can use double quote in echo too. No issues there. If it is conflicting, use double quote. Example echo "something";

    • This reply was modified 8 years ago by iSaumya.
    Thread Starter Glennf

    (@glennf)

    What about the <div class=”aicp”> ? It has double quotes in it.

    <?php
    if( aicp_can_see_ads() ) {
    // Shows the ad
    echo “<div class=”aicp”>”;
    }
    ?>

    Can I do this?

    <?php
    if( aicp_can_see_ads() ) {
    // Shows the ad
    echo “<div class=’aicp’>”;
    }
    ?>

    Plugin Author iSaumya

    (@isaumya)

    Hi,
    You can’t do this:

    <?php
    if( aicp_can_see_ads() ) {
    // Shows the ad
    echo “<div class=’aicp’>”;
    }
    ?>

    So, what you need to do is escape the similar quotes inside the start and end. Let’s say you want to say I can't dance. Not as can’t has a single quote in it if you are also using single quote for echo, it is gonna give isues. So, instead of using double quotes we can also escape the single quote in can’t using backslash \, so it would become echo 'I can\'t dance'; and it’s gonna work fine.

    Similarly, you can do this:

    <?php
    if( aicp_can_see_ads() ) {
    // Shows the ad
    echo "<div class=\"aicp\">";
    }
    ?>

    For more explanation you can watch this 1 min video here: https://www.youtube.com/watch?v=Y7qvGQtnEpg

    Thread Starter Glennf

    (@glennf)

    Thanks SO much. The escape sequence \’ worked.

    Plugin Author iSaumya

    (@isaumya)

    Glad to know that it helped.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Echo Command With Single Quotes Conflict ?’ is closed to new replies.