preg_replace / string_replace符号 - 或*到空格

时间:2015-12-08 08:58:15

标签: php jquery

我的数据:

-**abcd1234-*---
(类似于 - 和字符串中的*符号) 我想要数据输出:

abcd123

提前致谢!

1 个答案:

答案 0 :(得分:1)

有几种方法可以做到这一点。 字符串替换,如Ashish所述。

$input  = "-**abcd1234-*---";
$output = str_replace(array('-', '*'), '', $input);
echo $output;

如果你有大量的角色要剥离,也许这会更容易一些。

$input  = "-**abcd1234-*---";
$remove = "-*";
$output = str_replace(str_split($remove), '', $input);
echo $output;

当然,你可以使用正则表达式。

$input  = "-**abcd1234-*---";
$output = preg_replace('/[*-]/', '', $input);
echo $output;
相关问题