PHP Tips – Remove That Bad Character
There is a very common occurrence in websites. A bad character will appear on your web page for no reason whatsoever. Or so you thought…
Some amateur designers and developers can sometimes forget to play web-safe. Meaning your pound signs should be written £ rather than £ or your & symbols should be written &. However you perform it these simple lapses in using the correct web-safe format for the correct character can always slip through the net.
Perhaps you have a function that prints data from a database. Perhaps the data in that database is plain text – i.e text that is not web-safe. What can you do?
Well here is one tip for you. If you are printing out lots and lots of plain text onto your website and getting lots of <?> bad character signs try using this simple function:
<?php echo utf8_encode($message); ?>
This should solve that problem in most cases. It’s very simple and very quick and easy to implement. Next time you see a bad character just give utf8_encode a go – you never know it may fix everything!