从变量中提取逗号

时间:2011-05-09 19:52:52

标签: php

嘿那里,我有这个变量:

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

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

如何从$ blog_description中提取逗号和句点?  我想在我的网站标题中将其用作元描述。

1 个答案:

答案 0 :(得分:6)

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

或删除逗号和句点:

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

您也可以随时使用preg_replace:

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