ClarkySmiverz77 ClarkySmiverz77 - 1 year ago 46
PHP Question

Prevent breaking Syntax when using single quote in php

I have a php file that contains html. In the php file I echo sections of the html(Not the best way I know, but good for the time being).

I have started to apply AngularJs to this project and I am having a few problems with the syntax breaking in php.

for example ...

<!-- AngularJS -->
<div class='container' style='border: 1px solid black'>
<div class='row' ng-app='productsApp' ng-controller='ProductsController'>

<div ng-repeat='product in products | orderBy : | limitTo : 3' class='col-md-4' style='border: 1px solid; padding: 20px;'>
<h4>{{ }}<h4>


So referring to the example above, i'd like to alter the html to orderBy : '' ... but the single quotes is causing syntax errors.

Can anyone advise how to get around this problem?

Thanks in advance.

Answer Source

When outputting blocks of text, prefer using HEREDOC/NOWDOC:

echo <<<'END'
    <!-- AngularJS -->
    Rest of HTML here

This works well because you don't have to worry about nested quotes.