Question

I have a number of dynamically created pages, each has a number of keywords associated with it. I want to be able to create method that will assemble a little description of each page but I don't want them to all be the same.

I have a pool of sentences to choose from that are designed to accept the keywords. I am trying to create a technique that will take the ID of the page topic and select sentences based on it, so it is consistent every time you go to that page but different across different pages.

For example, so far I have

$noun = 'sheep farm';
$person = 'Farmer Dave';
$area = 'Herts';

$description1 = "This page is about $person";
$description2 = "This is $person's page";
$body1 = " he has $noun in $area";
$body2 = " he is based in $area and has a $noun";

What I want to do for farmer Dave, ID 123345 is select sentences based off his ID, so that when I create it he always has description 1 and body 2 - for example. Subsequently farmer John, ID 223454 Will always be created with description 2 and body 2. I know how to randomly select sentences but I don't know where to get started making them consistent.

I also have about 10 versions of each part and I have about 6 parts, I just chose two here for simplicity. I know it's potentially overkill but it adds a nice personal touch to the website.

Était-ce utile?

La solution

Give the conditions you given, I think below code maybe useful to you:

$ids = strval($user_id);

$desName = 'description'.$ids[0];
$bodyName = 'body'.$ids[1];
$userDes = $$desName;
$userBody = $$bodyName;

for lack of details, please leave a comment for code improvement.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top