-2
 echo "<br/>that will be" . " " . $pricetotal;

I need to add a uk "£" before the $pricetotal such that I see the following in the browser:

That will be £ 2.99

Albzi
  • 15,431
  • 6
  • 46
  • 63
Wambundu
  • 71
  • 4

5 Answers5

4

Just like that:

echo "<br/>that will be" . " £" . $pricetotal;

you can also use html entity:

echo "<br/>that will be &pound;" . $pricetotal;

or

echo "<br/>that will be &#163;" . $pricetotal;
lupatus
  • 4,208
  • 17
  • 19
  • True, in the first and third cases *if* you have set the encoding to be consistent with your source code. See http://stackoverflow.com/q/5056646/67392 – Richard Mar 04 '14 at 09:16
0

You could use

echo "<br/>that will be" . " £" . $pricetotal;

or

echo "<br/>that will be" . " &pound;" . $pricetotal;
Albzi
  • 15,431
  • 6
  • 46
  • 63
0

You can either try like

echo "&pound;";

Or even by character code you can try like

echo chr(163);
GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

You can use the HTMLEntity

echo "<br/>that will be &pound;" . $pricetotal;

Also make sure that your website is encoded with a multibyte charset which supports the £ char. I suggest using UTF-8. Include

<meta charset="utf-8">

in your <head> tag of your HTML.

Robin Webdev
  • 479
  • 2
  • 7
0

Both

echo "<br/>that will be" . " £" . $pricetotal;

and

echo "<br/>that will be &pound;" . $pricetotal;

work but under the following strict conditions:

  • meta charset should be set as utf-8 inside html head
<meta charset="utf-8" />
  • The php source code itself is encoded as utf-8 characters
  • The character encoding of browser should be utf-8. Normally, when setting meta charset as described above, the browser detects automatically that the html page is uncoded with utf-8

What is really important is that whole html rendering chain should be utf-8 to allow you to control your character encoding and to avoid strange behaviors. It is also the case when using for instance mysql database. The database encoding should be in advance and planned to be utf-8. Otherwise, it becomes very complex to rectify the encoding problem.

Ranaivo
  • 1,578
  • 12
  • 6