How to keep this code result on single line (no split). The result is displayed on a table and the column width is splitting the result in two lines. How to keep the output on single line? How to use the echo to fix that problem? Thank you!

$price = sprintf("%0.2f", $price); 

$parts = explode('.', $price);

echo "$parts[0] <span style = 'font-color: #ff0000; font-size:12px'><sup> ,$parts[1] USD</sup></span>";

enter image description here


2 Answers 2


You can prevent wrapping of text by using the white-space property in css:


  • Problem fixed: echo "$parts[0]<span style = 'white-space: nowrap; font-color: #ff0000;font-size:12px'><sup> ,$parts[1] USD</sup></span>";
    – Marius
    Commented Feb 20, 2015 at 5:58

I'm not a fan of inline styles like this but you could try adding a width to it.

echo "<span style='width:120px'>$parts[0] <span style = 'font-color: #ff0000; font-size:12px;'><sup> ,$parts[1] USD</sup></span></span>";
  • It is not working.
    – Marius
    Commented Feb 20, 2015 at 5:16
  • @Ben Robie's answer is correct. Commented Feb 20, 2015 at 15:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.