webmasters
webmasters

Reputation: 5831

Extract commas from variable

Hey there, I have this variable:

<?php $blog_description = get_bloginfo('description'); ?>

$blog_description ='I am a text, I have commas, and periods. And I want the text without them';

How can I extract the commas and periods from $blog_description? I want to use it as meta description in my website header.

Upvotes: 1

Views: 208

Answers (1)

Kelly
Kelly

Reputation: 41551

$blog_description = str_replace(',', '', get_bloginfo('description'));

Or to remove commas and periods:

$blog_description = str_replace(array(',','.'), '', get_bloginfo('description'));

You can always use preg_replace too:

$blog_description = preg_replace('/[,\.]+/', '', get_bloginfo('description'));

Upvotes: 6

Related Questions