Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:59:01+00:00 2026-05-31T13:59:01+00:00

What is the right way to use quotation marks ? echo ‘string’ . $variable

  • 0

What is the right way to use quotation marks ?

echo 'string' . $variable . 'anotherstring'; 

or

echo "string" . $variable . "anotherstring";

the problem of course comes to light when we need to print, return, or echo the quotaion mrk itself …

$output = '<div class="' . $class . ' " style =" ' . $style . ' ">' ;

or

$output = "<div class=' " . $class . " ' style =' " . $style . " '>" ;

??

And what about when some jQuery or Javascript enters the game ??

function o99_print_front_script() {
    return '
    <script type="text/javascript">
var pluginDir = " '. PHP_CONSTANT_X .' " ; 

  var cluster_styles = [{
        url:pluginDir +"/images/marker-o.png",
        background: "#c6c6c6"
        textColor: "#0f0"
    }];

      jQuery(document).ready(function() {
        jQuery("#example").example_func({
          elements:".div_1 .class_2",
           infobox: true,   
        map_opt: {zoom: 3,
        mapTypeId: google.maps.MapTypeId.ROADMAP},
        infobox_s:s_infobox_k,
        marker_icon:pluginDir +"/images/image_1.png"
});
});
</script>
    ' ;}

OR

function o99_print_front_script() {
    return "
    <script type='text/javascript'>
var pluginDir = ' ". PHP_CONSTANT_X ." ' ; 

  var cluster_styles = [{
        url:pluginDir +'/images/marker-o.png',
        background: '#c6c6c6'
        textColor: '#0f0'
    }];

      jQuery(document).ready(function() {
        jQuery('#example').example_func({
          elements:'.div_1 .class_2',
           infobox: true,   
        map_opt: {zoom: 3,
        mapTypeId: google.maps.MapTypeId.ROADMAP},
        infobox_s:s_infobox_k,
        marker_icon:pluginDir +'/images/image_1.png'
});
});
</script>
    " ;}

Is there some specification for this ? Some standard ? some “best practice” ?

Browsing through code you can see all kind of examples .

which one should we use for “first level” and which for “second” ?
And what if I have to “nest” 3 levels of those ??

this problem highlights itself when one uses some CMS , or system with “plugins” – and then wants to extend it with own code .the resulted HTML code in the DOM gets all confused, and you can not understand which quotes are which especially when JS is involved).

I am aware that all of them will work, but I want to know which one is right and which is wrong (if such terms exists in regarding this).

EDIT I

After reading comments / answers – I have realised that maybe I wrote the question in an unclear fashion. my question is regarding the Outputted xHTML /JS .
Of course that it has direct consequences on the PHP part , but mainly I was wondering what is the best practice to maintain a consistent and uniformal code throught the finished document while maintaining an easy syntax on the back-end..
Even looking at the source of this very page here (this stackexchange site) one can see some inconsistent behavior (at least to me it looks like it )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:59:03+00:00Added an answer on May 31, 2026 at 1:59 pm

    About markup nesting I would strongly suggest to adopt the MVC pattern so you will obtain a clear separation of the view (your html template) from the controller part (what you have to put in the template). In this way you can avoid to make a “soup” of unmantainable markup and php code

    Anyway for the markup part I prefer writing like so

    echo "string $variable anotherstring";
    

    since PHP variables are parsed when included in a string with double-quote delimiters. For long code blocks like the javascript part another possibility is to use HEREDOC syntax so you can write php variables like this

    $jssnippet = <<<EOJS
       <script type='text/javascript'>
       var pluginDir = '{$PHP_CONSTANT_X}' ; 
       ...
    EOJS;
    

    See also http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
    hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble trying to find the right way to use MSBuild to build
What's the right way in Drupal to create reports? I was hoping to use
Is this the right way to return an object from a function? Car getCar(string
Which is the right way to use the front or the rear camera using
Is this the right way to use delete[] operator? int* a=new int[size]; delete[] a;
Possible Duplicate: What’s the Right Way to use the rand() Function in C++? When
What's the right way to use a monospaced font for all text in a
I am trying to find the right way to use a Generic List of
I was wondering what is the right way to use PHP in an Object
What's the right way to use the arguments property of a function? This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.