Skip to content
Advertisement

Using PHP variable in HTML attribute cuts off words with space inbetween [closed]

echo "<li class='product-results-item' article-name=" . $product->article_name . ">" . $product->article_name . "</li>";

When echoing this line, the article-name attribute gets cut off, meaning that Single Bed becomes Single.This does not happen for the article_name text between the <li> tags

How can I overcome this problem?

Advertisement

Answer

There are missing (single) quotes around attribute value.

echo "<li class='product-results-item'  article-name='" .  $product->article_name .  "'>". $product->article_name. "</li>";
                                                     ^                                ^
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement