2

I am using this code to store HTML code in a variable called $conversions

$conversions = "GBP " . number_format($file*0.84) . "CHF " . number_format($file*1.23) 

However I can't seem to figure out how to add a <br> before the word "CHF ".

Any ideas?

The whole code is as follows:

<?php
$file = get_field('fl_price');
if(trim($file) == ""){echo 'Price on Application' ;}else{$conversions = "GBP " . number_format($file*0.84) . "<br />CHF " . number_format($file*1.23)  ;echo 'EUR ' . number_format($file) . "</br><a class=\"wp-tooltip\" title=\" $conversions \">Other Currencies</a>" ;}
?>
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
JoaMika
  • 1,727
  • 6
  • 32
  • 61
  • Where's the line of PHP that `echo`s the contents of `$conversions`? Also, why can't you just change `"CHF "` to `"
    CHF "`? Also, try reading about [what makes a good question](http://stackoverflow.com/help/how-to-ask). Help us to help you.
    –  Oct 06 '13 at 23:37
  • Have you tried adding it in the quotes? – mario Oct 06 '13 at 23:37
  • i have posted the full code.. your answer doesn't work.. – JoaMika Oct 06 '13 at 23:40
  • possible duplicate of [How can I use a carriage return in a HTML tooltip?](http://stackoverflow.com/questions/358874/how-can-i-use-a-carriage-return-in-a-html-tooltip) – Tim M. Oct 06 '13 at 23:57
  • Possible duplicate of [newline in ](http://stackoverflow.com/questions/246438/newline-in-td-title) – ficuscr Aug 24 '16 at 18:02
  • You want a carriage return (` `) or a line feed (` `), not a `
    `. Seeing many outdated/wrong answer. Better thread here: http://stackoverflow.com/questions/246438/newline-in-td-title
    – ficuscr Aug 24 '16 at 18:04

3 Answers3

1
$conversions = "GBP " . number_format($file*0.84) . "&#xA;CHF " . number_format($file*1.23);

Echoing $conversions will now have a HTML-linebreak before CHF.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
  • html is output like this
    EUR 1,000,000
    – JoaMika Oct 06 '13 at 23:45
  • The output is not normal HTML, but the content of a title-attribute. You should read http://stackoverflow.com/questions/246438/newline-in-td-title (in other words, replace `
    ` with ` `)
    – OptimusCrime Oct 06 '13 at 23:47
  • I made a fiddle in my answer. It definitely works for me in Chrome, but that's the only place I've tested. Possibly a browser issue, or you're introducing a typo of some sort in your code. – Yevgeny Simkin Oct 06 '13 at 23:55
1

You are adding your string to an attribute of <a> called title. This isn't going to be displayed and is certainly not going to render any HTML (like a br tag).

edit:

As per OptimusCrime's suggestion, this does work: http://jsfiddle.net/5rM4u/1/

Replace your <br/> with &#xA; and you're good to go.

Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236
  • this works actually without the "
    ".. the problem is adding a breaking line
    – JoaMika Oct 06 '13 at 23:46
  • I've edited your question to reflect what you're actually asking. This has absolutely nothing to do with PHP. You're simply trying to add a line break to the `title` element of an `Anchor` tag. OptimusCrime's suggestion appears correct. – Yevgeny Simkin Oct 06 '13 at 23:50
  • Using Firefox - HTML Output is this but it doesn't give a new line:
    EUR 1,000,000Other Currencies
    – JoaMika Oct 06 '13 at 23:55
  • Works in FF 24.0. http://jsfiddle.net/5rM4u/2/ (and Chrome, Opera, Safari and IE10) – OptimusCrime Oct 06 '13 at 23:57
  • ok the problem actually lies with the way this plugin renders the tooltip - I can momentarily see the breaking line before the document fully loads but when wp-tooltip kicks in the breaking line is removed.. http://wordpress.org/plugins/wp-tooltip/ – JoaMika Oct 07 '13 at 00:03
  • i don't suppose anyone here is so heisenberg to go into the plugin and sort this out :( – JoaMika Oct 07 '13 at 00:04
0

You are trying to print the $conversions variable in the "title" of the "a" tag. just using <br /> will not work.

See some of the answers to this question "How can I use a carriage return in a HTML tooltip?" it may contain the answer that you are looking for.

Community
  • 1
  • 1
Onema
  • 7,331
  • 12
  • 66
  • 102