Forums

Comment Body - Convert Ampersands [Solved]

warriorgov79 30 Sep, 2010
Does anyone know a PHP script to convert ampersands to its HTML entity (& amp;) in the comment body? I don't know PHP, so I've been manually editing comments to validate HTML.

I can see where I would need to insert it in components/com_chronocomments/templates/comment-item.html.php. Just don't know how to go about it to achieve the desired result. Thanks for any help.

Ben
GreyHead 30 Sep, 2010
Hi Ben,

It will be something like this
$text = str_replace('&', '&', $text);
$text = str_replace('&', '&', $text);
The second line is to fix any existing &

Bob
warriorgov79 30 Sep, 2010
Thanks Bob. I understand the str_replace part.

If this is the section I want to edit:
<div class="comment-body">
      {comment_text}
</div>

How would I write the script?

Ben
GreyHead 30 Sep, 2010
Hi Ben,

Sorry, can't help with that part. I've never dug into the ChronoComments code enough to understand how it works :-(

Bob
warriorgov79 29 Nov, 2010
Hi Bob,

I figured it out. I added the 2 lines you suggested to /plugins/content/ChronoComments.php around line 341, after the bbcode and htmlcode arrays just above:

$newtext = preg_replace($bbcode, $htmlcode, $text);

So the code looks like this:
$text = str_replace ('&', '&', $text);
$text = str_replace('&amp;', '&', $text);
$newtext = preg_replace($bbcode, $htmlcode, $text);		
$newtext = nl2br($newtext);
return $newtext;

Works like a charm. Thanks for your help!

Aloha,
Ben

Update: If you also have the module installed, the same must be done for /modules/mod_chronocomments/helper.php around lines 111 and 148.
dyn87 26 Oct, 2011
Thanks for posting that solution. It just came in really handy on a project I was working on and is going to save me a lot of time!!! I love this forum already 😀
This topic is locked and no more replies can be posted.