dongrong7267 2017-05-19 15:00
浏览 196
已采纳

从逗号中的字符串中删除逗号,空格,句点

Users submit names in two separate fields: firstname(author_fname) and last name (author_lname) Entries are sometimes Smith, John J. or John and Mary Smith, or john j. smith. I need to get all extraneous characters out of the submission, so the name comes up with just the words: smithjohnj or johnandmarysmith. Using trim, I was able to delete the white space.

But I would like to get the comma out as well. Ex:

$text = $results["author_lname"].$results["author_fname"];
$trimmed = trim($text);
var_dump($trimmed);
$Aname = $trimmed;
  • 写回答

1条回答 默认 最新

  • dronthpi05943 2017-05-19 15:30
    关注

    for this you can use the php method: strtr as explained here: http://php.net/manual/en/function.strtr.php

    In your case you could use strtr with your already trimmed string like this:

    $stripped = strtr($trimmed, array(',' => ''));
    

    This should do the trick.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么我按照电路图做出的仿真和实物都不能使用
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web