StuBlackett
StuBlackett

Reputation: 3857

Convert multibyte character sequence to HTML entity

I've got a page that pulls through categories. However I have a charset issue in that all the bulleted items in the list are coming through as "•" so what I'd like to do is replace them with the correct HTML Enc Type of "•"

I've created script that can ECHO this out, BUT I need to try and achieve this on page load if possible?? So any ideas appreciated.

My code is :

[PHP]

<?php
 $search = array("•");
 $replace = array("&#x2022;");
?>

[HTML]

<span style="color: rgb(255, 255, 255); font-size: 14pt;"><span style="font-family: Verdana;"><span style="font-weight: bold;"></span></span></span><span style="font-family: Verdana; color: rgb(186, 66, 101); font-weight: bold;"><br />
    <br />
    •</span><span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(105, 105, 105);"><span style="color: rgb(186, 66, 101);"></span> <span style="font-size: 8pt;">Impellers for drinks mixers</span></span></span>.<br style="font-family: Verdana; color: rgb(105, 105, 105);" />

<span style="font-family: Verdana; color: rgb(186, 66, 101); font-weight: bold;">•</span><span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(105, 105, 105);"><span style="color: rgb(186, 66, 101);"></span></span></span><span style="font-family: Verdana; color: rgb(105, 105, 105);"> <span style="font-size: 8pt;">Additional malt cups.</span> </span><br style="font-family: Verdana; color: rgb(105, 105, 105);" />
<span style="font-family: Verdana; color: rgb(186, 66, 101); font-weight: bold;">•</span><span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(105, 105, 105);"><span style="color: rgb(186, 66, 101);"></span></span></span><span style="font-family: Verdana; color: rgb(105, 105, 105);"> <span style="font-size: 8pt;">Blender containers</span></span>.<br style="font-family: Verdana; color: rgb(105, 105, 105);" />
<span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(255, 69, 0);"></span></span><br />
<span style="font-family: Verdana;"><span style="color: rgb(91, 91, 91);"><br />

        </span></span><br />
<?php echo str_replace($search,$replace,"•"); ?> 

Upvotes: 0

Views: 444

Answers (3)

WEBProject
WEBProject

Reputation: 1345

Just do it on php.

$toPrint = <<<EOF

<span style="color: rgb(255, 255, 255); font-size: 14pt;"><span style="font-family: Verdana;"><span style="font-weight: bold;"></span></span></span><span style="font-family: Verdana; color: rgb(186, 66, 101); font-weight: bold;"><br />
    <br />
    •</span><span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(105, 105, 105);"><span style="color: rgb(186, 66, 101);"></span> <span style="font-size: 8pt;">Impellers for drinks mixers</span></span></span>.<br style="font-family: Verdana; color: rgb(105, 105, 105);" />

<span style="font-family: Verdana; color: rgb(186, 66, 101); font-weight: bold;">•</span><span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(105, 105, 105);"><span style="color: rgb(186, 66, 101);"></span></span></span><span style="font-family: Verdana; color: rgb(105, 105, 105);"> <span style="font-size: 8pt;">Additional malt cups.</span> </span><br style="font-family: Verdana; color: rgb(105, 105, 105);" />
<span style="font-family: Verdana; color: rgb(186, 66, 101); font-weight: bold;">•</span><span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(105, 105, 105);"><span style="color: rgb(186, 66, 101);"></span></span></span><span style="font-family: Verdana; color: rgb(105, 105, 105);"> <span style="font-size: 8pt;">Blender containers</span></span>.<br style="font-family: Verdana; color: rgb(105, 105, 105);" />
<span style="font-family: Verdana; color: rgb(105, 105, 105);"><span style="color: rgb(255, 69, 0);"></span></span><br />
<span style="font-family: Verdana;"><span style="color: rgb(91, 91, 91);"><br />

        </span></span><br />

EOF;

echo str_replace($search,$replace,$toPrint);

Upvotes: 1

jdhartley
jdhartley

Reputation: 486

Rather than this:

<?php echo str_replace($search,$replace,"•"); ?> 

all of the previous HTML should be where the • is. For example, if you put all of your category HTML into a string $categories, you would do something like this:

<?php echo str_replace($search, $replace, $categories); ?>

That way the str_replace edits the HTML rather than that string.

Upvotes: 1

Luka
Luka

Reputation: 1718

I suppose you're generating HTML code with PHP. If I'm right, you should put the replacement code inside your generating PHP script and carry out all the replacements on the server before sending code back to browser.

Upvotes: 1

Related Questions