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

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.