1

I have this php code with an html for a loop

if($contenido_index === 1 || $contenido_index === "1") {   
                                                   echo "
        <div class='portcontrol'>
            <div class='info_container cssemigrey'>
                <a href='". $contenido_link."'><h2 class='naranja'>". $contenido_titulo."</h2></a>
            </div>

            <div class='wrapimg'>
                <a href='". $contenido_link."'><img alt='Image de ". $contenido_titulo."' src='". $contenido_imagen."'></a>
            </div>
        </div>
";}

I dont want to change for example href=" " for this href=' '

Is there any other way to write it so I can paste the normal HTML code that i'm going to use for a loop.

3
  • 1
    Take a look at HERDOC or NOWDOC Commented Jun 10, 2015 at 14:19
  • Why two checks for $contenido_index? Commented Jun 10, 2015 at 14:20
  • Olly Tenerife i'm using wordpress pods pluging to work on it, its safier to do the both checks, Commented Jun 10, 2015 at 14:55

2 Answers 2

1

Just figure it out from a joomla template...

<?php if($contenido_index === 1 || $contenido_index === "1"): ?>
  <div class="portcontrol">
              <div class="info_container cssemigrey">
                    <a href="<?php echo $contenido_link; ?>"><h2 class='naranja'>"<?php echo $contenido_titulo; ?></h2></a>
                </div>

                <div class="wrapimg">
                    <a href="<?php echo $contenido_link; ?>"><img alt="Image de <?php echo $contenido_titulo; ?>" src="<?php echo $contenido_imagen; ?>"></a>
                </div>
            </div>
<?php endif; ?>
Sign up to request clarification or add additional context in comments.

3 Comments

can you tell how's it's better?
why to use multiple <?php ?> if it can done through only one. please specify why it's better. otherwise don't say that this is better.
Because you don have to modify the HTML from " to '
1

Change echo " for echo '

That way you won't have to escape double-quote marks in the HTML you are echoing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.