Help me write this code correctly

Asked

Viewed 109 times

-3

The following code is part of a php script that I’m developing, it works, but I feel like I’m writing a gambiarra because of the placement of the quotes and double quotes. Can you tell me if I can leave the code just like that?

print '<div class="titleebay"><a rel="nofollow" href="'. $product['link_produto'] . '">"' . $product['nome'] . '"</a></div>';
print '<div class="mainproduct"><a rel="nofollow" href="' . $product['link_produto'] . '"><img style="height:120px" src="' . $product['link_imagem'] . '"/><br/>';
//print "De:;&nbspR$". $preco_normal . "<br/>";
print '<span>Apenas&nbspR$"' . $product['preco_promocao'] . '"<br/></a></span></div>';
//print "Em&nbsp" . $parcelas . "x de&nbsp:&nbspR$" . $vl_parcelas . "</a></span></div>";           

}

  • You can use the printf() or here/Nowdoc in place of these prints.

  • 1

    There is no "dislike" in stackoveflow, but downvotes. And they usually point to poor quality questions, lack of more information about the problem or lack of clarity.

  • Big differences, man, like trading Satan for Lucifer. The question is very clear.'

2 answers

1


Face what I always do and use HTML with PHP and not PHP with HTML, ie.

<div class="titleebay">
    <a rel="nofollow" href="<?= $product['link_produto']  ?>"><?= $product['nome'] ?></a>
</div>

-1

You can send the product to view in object format, it is easier for you to work. Adapted your code I would do something like this:

$productObj = (object) $product;
print("<div class='titleebay'><a rel='nofollow' href='$productObj->link_produto'>$productObj->nome</a></div>");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.