0

I have the following code in the page title, on 1500 pages all the same

$title = "Detail --Homes For Sale";

and would like to extract the first 80 characters from the description into the title, so that each page has a unique title.

the description code is like below,

<?=nl2br(stripslashes(substr($emlaklist->aciklama,0,200)))?>

any suggestions how this can work?

antalya
  • 85
  • 6

3 Answers3

2

You just need to utilise substr() function for your title.

You would do it like substr($string, 0, 80); where $string is the variable that holds the description, 0 is the start of the string and 80 is where the string you want ends.

Here is what I think you're after based on your question

$description = stripslashes(substr($emlaklist->aciklama,0,200));

$title = substr($descripton, 0, 80);
Andy Holmes
  • 7,817
  • 10
  • 50
  • 83
1
$title = "Detail --Homes For Sale";

$description = stripslashes(substr($emlaklist->aciklama,0,80));

$title = $title . " " . $description;
GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
  • these are good answers but i am no expert. could you please provide how i would need to write this $title = "Detail --Homes For Sale"; – antalya Jul 21 '14 at 07:55
  • What are you actually wanting to achieve - from what you have written it looks like every page has the title 'Detail --Homes For Sale' - this is stored in a variable and echoed out into the page. The answer I gave assumes you want to keep the first part and append the first 80 characters from the description to the end to give 'Detail --Homes For Sale First 80 characters from description...' is this not what you want? – GrahamTheDev Jul 21 '14 at 07:58
  • here is the page, i would like the title to extract 80 characters of the description to make the page titles unique http://www.turkish-property-world.com/detail.php?KKId=2965&Ino=3 – antalya Jul 21 '14 at 08:08
  • for example i would like to have the titles show as so $title="LUXURY SEAVIEW VILLA for sale in Tepe Alanya" – antalya Jul 21 '14 at 08:10
  • Then you just need to set `$title = stripslashes(substr($emlaklist->aciklama,0,80));` then inside the title tags just do `` – GrahamTheDev Jul 21 '14 at 08:20
  • could you please explain more details for above exmple i think we are close. must not stripslashes(substr($emlaklist->aciklama,0,80)); be within quotes to function, otherwise it just shows as written. – antalya Jul 21 '14 at 15:36
1

You will also have to make sure, that your variable ($emlaklist) is already set, where you want to append it's value to the $title variable.

In general you might try to copy the code-part that starts with $emlaklist = .. to the place before your $title =, but most likely this will be a database request, so you might need to take other code into account, that contributes to getting that value ...

Other than that, the other answers here will be very well able to handle the shortening of your description, etc.

(Sry that this is too long for a comment, but it might be helpful anyway.)

Levite
  • 17,263
  • 8
  • 50
  • 50