PHP force commas between words

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
I'm messing around with a very basic content managment system and its meta tags and wondered if there's a way to add the page title into the keyword meta tags but seperate each word with a comma?

For the title meta I have <title>{title}</title> using a sort of tpl system, and I have the same thing in the keywords meta tag. i.e.
<meta name="keywords" content="{title}" />

Which isn't so bad, especially as many search engines ignore the keyword meta tag anyway, but I'm curious to know how the word seperation is done as I saw today that Youtube somehow has video titles in the keyword meta tag seperated by commas.

I mean I guess I have to have something like in a php file somewhere:

$keywords = $title then some code here to seperate it;

Any ideas?
 

Whipped

Part of the furniture
Joined
Dec 22, 2003
Messages
2,155
If you're meaning you want to change something like "This is the title of the page" to "This,is,the,title,of,the,page" then you can use a simple explode and implode.

Code:
$title = 'This is the title of the page';
$keywords = implode(",",explode(" ",$title));

This splits the title string by spaces into an array and then reassembles that array with ,

You could also just replace spaces with commas in the string using a str_replace

Code:
$keywords = str_replace(" ",",",$title);
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
I'll try that. I never even heard of implode and explode before, thanks for teaching me something. :)
 

Users who are viewing this thread

Top Bottom