结合两个字符串 - 特殊情况

I have all my text defined in separated language files, meaning if I write:

Example 1 (working):

echo TEXT_FOR_PRODUCT_TENNIS; 

The text defined depending on your language for TEXT_FOR_PRODUCT_TENNIS is shown on the site (for example: "Great tennis products!".

BUT if I try to combine two strings in order to create and echo TEXT_FOR_PRODUCT_TENNIS, it is not working. Instead of picking up the text from the language file, it just echoes "TEXT_FOR_PRODUCT_TENNIS" on my site:

Example 2 (not working):

$first_part = TEXT_FOR_PRODUCT_;
$products_name = TENNIS;
echo $first_part.$products_name; 

Why can't I combine two strings like this, so that the text defined in the language file is showing as it does in my first example?

here goes your solution :-

define('TEXT_FOR_PRODUCT_TENNIS','dfbvzdfb');
$first_part = 'TEXT_FOR_PRODUCT_';
$products_name = 'TENNIS';
echo constant($first_part.$products_name); 

you first defined a constant and the defined two variable with string value then print it,how the php differentiate between these two.

note : constant called without '$' sign.

Example 2 didn't work because you'd defined whole TEXT_FOR_PRODUCT_TENNIS

try to use array for your project like :

$array = array('TEXT_FOR_PRODUCT_TENNIS' => "something" , ... and so on);

then use your code:

$first_part = 'TEXT_FOR_PRODUCT_';
$products_name = 'TENNIS';
echo $array[$first_part.$products_name];