php ltrim many characters at once

时光总嘲笑我的痴心妄想 提交于 2021-02-05 11:00:46

问题


Hi is there a better and faster way to clean many characters from beginning of a string?

I have this one, but is this really the fastest way?

$description_new = ltrim($description_new, '###');
$description_new = ltrim($description_new, '.');
$description_new = ltrim($description_new, ',');
$description_new = ltrim($description_new, '!');
$description_new = ltrim($description_new, '?');
$description_new = ltrim($description_new, ')');
$description_new = ltrim($description_new, '(');

Thanks Nik


回答1:


the second parameter can be a charlist:

$description_new = ltrim($description_new, '#.,!?()');

You could also add a range of characters if it would suit your needs:

$clean = ltrim($binary, "\x00..\x1F");

Read about: function.ltrim



来源:https://stackoverflow.com/questions/16383965/php-ltrim-many-characters-at-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!