[英]Remove one or more dots at beginning of string
How can I remove the dot that starts a string? 如何删除启动字符串的点?
$string = ". Hello world .";
I only want to remove the first dot, not the dot at the end. 我只想删除第一个点,而不是最后一个点。
ltrim('. Hello World! .','.');
Simple pattern would match any period (or sequence, since you suggested this) at the start of a string, or (following a request from the OP in the comments below) at the end of the string: 简单模式将匹配字符串开头的任何句点(或序列,因为您建议这一点),或者在字符串末尾(在下面的注释中来自OP的请求之后)匹配:
preg_replace( "/^\.+|\.+$/", "", "....Hello...." );
Demo: http://codepad.org/Nst5EX1k 演示: http : //codepad.org/Nst5EX1k
Using $stripped = trim($string, ' .');
使用
$stripped = trim($string, ' .');
is probably better and strips any space or dot. 可能更好,剥去任何空间或点。
It seems to me that you're using PHP. 在我看来,你正在使用PHP。 Try:
尝试:
$string = ". Hello World! .";
$pos = strrpos($string, ".");
$stripped = substr($string, $pos + 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.