Get PHP str_replace to work with Joomla

As you may know, Joomla components enable you to override their output by copying their template files into your site template. Joomla components generally use helper files which cannot be overridden.

I have a helper.php file that includes the string:

$specific_fields_text = ''.$specific_field_title.': '.$specific_fields[$i]->text.' '.$specific_fields[$i]->description.'';

In my template override is the code:


  specific_fields); ?>

The output is as follows:


    //.....etc......//
title value
title value

Basically I want to get rid of the table and turn it into a definition list but I cannot modify the helper.php file. I am thinking that the answer is to do with str_replace

I have tried using:

specific_fields); $spec_fields_dl = str_replace("'.$specific_field_title.': '.$specific_fields[$i]->text.' '.$specific_fields[$i]->description.''", "
'.$specific_field_title.':
'.$specific_fields[$i]->text.' '.$specific_fields[$i]->description.'
'", $spec_fields); echo $spec_fields_dl; ?>

This returns all of the text but with no html tags (no tr, td, dt, etc).

You can easily parse table data with PHP, like in this example:

$doc = new DOMDocument();
$doc->loadHTML(koparentHTML::getHTMLSpecificFields($this->specific_fields));

$rows = $doc->getElementsByTagName('tr');

$data = array();
for ($i = 0; $i length; $i++) {
    $cols = $rows->item($i)->getElementsbyTagName("td");
    $data[$cols->item(0)->nodeValue] = $data[$cols->item(1)->nodeValue];
}

var_dump $data;

This should convert your table into assoc array (‘title’ => ‘value’). I hope it helps.

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Get PHP str_replace to work with Joomla

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录