A small problem

I have a “cluster” of amazon link, automatically generated from a) general keywords (common to my websites: plain text), b) particular keywords (of that php file: $keywords).

My previous code was:

$keys_olon="$keywords, [some fixed plain text words, comma separated]";

Where $keywords are defined as variable in (almost!) each php file of my website.

And I called the code with this one:

    echo " <p id=\"amazonkeys\" class=\"center amazon\">search <b>on Amazon</b> about: ";
    foreach (explode(',', $keys_olon) as $key) {echo "<a rel=\"external\" href=\"https://www.amazon.it[my-amazon-code\">$key</a> ";}
    echo ".</p>";

I managed to avoid the last comma with this css

#amazonkeys a:after {content:','}
#amazonkeys a:last-child:after {content:''; margin-right: -4px;}

The problem is that I would add the specific keywords as above ($keys_specifiche, different for my each of my websites) . And the new code would be:

$keys_olon="$keywords,$keys_specifiche,  [some fixed plain text words, comma separated] ";

With this code, if a php file is without particular keywords (that is $keywords), I get an annoying comma at the beginning of the (links to amazon) list.
Any idea, either with php or css?
Thank you!

How about

$keys_olon = $keywords . ($keywords == "" ? "": ",") . $keys_specifiche . ",  [some fixed plain text words, comma separated] ";
1 Like

It is ok. You solved my problem. :grinning:
Thank you very, very much!