替换表中的字符串

时间:2015-03-09 12:22:25

标签: php html magento

我必须检查字符串并替换属性是否等于" Destaque:"如果属性匹配则无法打印该行,但我对这些功能感到困惑,有人可以帮助我吗?

<?php

class Produto_Atributo
{
    function __construct()
    {
    }


    function produtoAtributo($codigo)
    {
        Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

        $banco_magento = Mage::getSingleton('core/resource')->getConnection('core_write');


        $sql = "SELECT * FROM tw_produto_atributo where entity_id=" . $codigo;


        $resultadoSql = $banco_magento->fetchAll($sql);

        $count = 0;

        foreach ($resultadoSql as $linha) {

            $classe = '';

            if ($count % 2 == 0) {
                $classe = 'par';
            }
            else {
                $classe = 'impar';
            }

            $_atributo = $this->recuperarAtributo($linha['attribute_id']);


            $_optionText = $this->recuperarOptionid($_atributo, $linha['option_id']);
            $descricao=$linha['ds_conteudo'] ;
            $order   = array("\n");
            $replace = '<br />';
            $newstr = str_replace($order, $replace, $descricao);


            if (isset($linha['ds_conteudo']) && $linha['ds_conteudo'] != '') {
                echo '<tr class="active '.$classe.'">

                <td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important; "> ' .  ucwords( strtolower($_optionText)) . '</td>

                <td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $newstr. '</td>
            </tr>';
            } else {
                echo '<tr class="'.$classe.'">
                <td  class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important;">'if($_atributo->getFrontend_label()==!"Destaque:"){$_atributo->getFrontend_label();}else {'Loko'.$_atributo->getFrontend_label();} '</td>

                <td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $_optionText . '</td>
                </tr>';
            }

            $count = $count + 1;

        }
    }

    function recuperarAtributo($atributo)
    {

        $cod = $atributo;

        $attr = Mage::getModel('eav/entity_attribute')->getCollection()->addFieldToFilter('attribute_id', array('eq' => $cod))->getFirstItem();

        return $attr;

    }

    function recuperarOptionid($atributo, $option_id)
    {

        return ($atributo->getSource()->getOptionText($option_id));

    }
}

1 个答案:

答案 0 :(得分:0)

已经哈哈了 非常简单,这就是答案:

  if (isset($linha['ds_conteudo']) && $linha['ds_conteudo'] != '') {
                echo '<tr class="active '.$classe.'">

                <td class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important; "> ' .  ucwords( strtolower($_optionText)) . '</td>

                <td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $newstr. '</td>
            </tr>';
            } else {
                if($_atributo->getFrontend_label()<>"Destaque:"){
                    echo '<tr class="'.$classe.'">
                        <td  class="table-caracteristica-titulo" style="padding-left: 45px !important;padding-right: 45px !important;">' . $_atributo->getFrontend_label() . '</td>

                        <td class="table-caracteristica-descricao" style="padding-left: 45px !important;padding-right: 45px !important;"> ' . $_optionText . '</td>
                        </tr>';
                }

            }