Search code examples
phphtmlposttrim

removing line breaks in php


As the title reads I am using the echo function to create an h3 string which will insert a php value $lowprice and $highprice. The goal is to have the text read

Here are all the houses whos prices are between $lowprice and $highprice. The code breaks into individual lines like this

Here are all the houses whose prices are between $

100000 and $

500000 :

This is the code I have written, how do I get it all onto one line.

<?php
echo '<caption>';
echo '<h3> Here are all the houses whose prices are between $ </h3>'.$lowprice.'<h3> and $</h3>'.$highprice.'<h3> : </h3>';
echo '</caption>';
?>

Solution

  • <h3> is a block element, meaning it will take up a whole line. I think you want to replace your inner <h3>'s with <span> tags which are inline elements:

    Like this:

    <?php
      echo '<caption>';
      echo '<h3> Here are all the houses whose prices are between $ <span>'.$lowprice.'</span> 
      and $<span>'.$highprice.'</span></h3>';
      echo '</caption>';
    ?>
    

    Or you can simply remove all the inner tags all together, like this:

    <?php
      echo '<caption>';
      echo '<h3> Here are all the houses whose prices are between $'.$lowprice.' and $'.$highprice.'</h3>';
      echo '</caption>';
    ?>