Jump to content

[SOLVED] Assign third word in page titles to a variable


alconebay

Recommended Posts

Say I have a car website and the structure of the page titles will always be something like:

 

"The Carguide's Camero Information."

 

All my page titles will follow this format so I want to be able to assign the third word of the page title (in this example, "Camero") to a variable that I can use throughout the page.

 

Is this where that "explode" function comes in? Thanks

Say I have a car website and the structure of the page titles will always be something like:

 

"The Carguide's Camero Information."

 

All my page titles will follow this format so I want to be able to assign the third word of the page title (in this example, "Camero") to a variable that I can use throughout the page.

 

Is this where that "explode" function comes in? Thanks

 

I guess you could use explode... not sure how your code is layed out though...

 

$t = "The Carguide's Camero Information.";

$t_arr = explode(" ", $t);

echo $t_arr[2]; // Camero 

Thanks! That works beautifully. Here is how I'm using it in my site:

 

<head>

<?php $title="The Carfan Camero Page";

$title_arr = explode(" ", $title);?>

<title><? echo $title; ?></title>

</head>

 

<html>

Welcome to the <? echo $title_arr[2]; ?> page of Carfan.

</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.