Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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,"•"); ?> 
share|improve this question
2  
why don't you correct the charset problem instead ? – Shrinath Feb 7 '11 at 12:22
Unfortunatley this creates another error. Doing this char set replacement is an easier fix – StuBlackett Feb 7 '11 at 12:25

3 Answers

up vote 1 down vote accepted

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);
share|improve this answer
I cant do that, I dont think? The file is coming from a description field in the Database which is full of the HTML I pasted above. – StuBlackett Feb 7 '11 at 14:14
what exactly do you get from the DB? – WEBProject Feb 7 '11 at 18:03
The code above is in the DB field - Description – StuBlackett Feb 8 '11 at 9:15

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.

share|improve this answer
Thanks for that. Problem I have is the categories page is created dynamically using Smarty and a Database. The database field is what's giving the HTML as posted above. So I need to find a way of intercepting that data or replacing it. I'm going to look at MySQL Triggers. – StuBlackett Feb 7 '11 at 14:12
How are you outputting your content with smarty? Can you access the variable it is outputting (I am guessing it is using something like {$name} or similar syntax) and then edit that with PHP? – jdhartley Feb 7 '11 at 21:07
I'll have a hunt through the Smarty Code. Its software built by X-Cart. I have tried an MySQL Trigger to replace for &bull; – StuBlackett Feb 8 '11 at 9:17

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.

share|improve this answer
Its coming through from a Database Field that is full of HTML - X-Cart software :/ – StuBlackett Feb 7 '11 at 14:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.