$uuid = {3D0E2ECA-C35C-4826-82B1-5C00F8F9C9F2};
$id = str_replace("-","","$uuid");
echo $id;

我想把$uuid中得"-"和{};都替换掉输出,我这样编怎么没反映啊!

推荐图书

  • O'Reilly:Head First PHP & MySQL(中文版)


1个回答

正则

$uuid ='{3D0E2ECA-C35C-4826-82B1-5C00F8F9C9F2}';
$id = preg_replace('/[-\{\}]+/','',$uuid);
echo $id;

替换

$uuid ='{3D0E2ECA-C35C-4826-82B1-5C00F8F9C9F2}';
$rb = array('-','{','}');
$rc = array('','','');
$id = str_replace($rb,$rc,$uuid);
echo $id;