CodeIgniter Forums

Full Version: htmlentities() question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Typeslowly[/eluser]
Hi,

Not strictly CI but always find this the best place to clear things up so thanks in advance for any insight.

I am trying to use htmlentities() to convert special characters.

This works as expected and outputs 'what and the html entity for &' which is great.

Code:
$test_string = 'what &';
$test_string = htmlentities( $test_string, ENT_QUOTES, 'UTF-8' );
echo '<p>hey: '.$test_string.'</p>';

This outputs nothing when I introduce £

Code:
$test_string = 'what & £';
$test_string = htmlentities( $test_string, ENT_QUOTES, 'UTF-8' );
echo '<p>hey: '.$test_string.'</p>';


Am I missing something?

El Forum

[eluser]zreedeecom[/eluser]
Is your document UTF8 encoded?

El Forum

[eluser]Typeslowly[/eluser]
[quote author="zreedeecom" date="1286481169"]Is your document UTF8 encoded?[/quote]

Hi zreedeecom,

Thanks for your reply, yes the document is UTF8 encoded, here is the html:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;Testing Special Characters&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php    
// Testing encoding
$test_string = 'what?&';
$test_string = htmlentities( $test_string, ENT_QUOTES, 'UTF-8' );
echo '<p>hey: '.$test_string.'</p>';
?&gt;
&lt;/body&gt;
&lt;/html&gt;

El Forum

[eluser]Typeslowly[/eluser]
Used ascii_to_entities()

Pretty simple when you read the manual, see text_helper in the manual.

:-)

Jason