[英]Replace last occurrence to end of string using Twig preg_replace
[英]Make a preg replace on string in twig
我试图找到一种方法来在树枝上制作它,但我找不到解决方案..
preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', ucfirst("thisIsAnExample")) ;
php 中的输出是“这是一个例子”
是否可以在 twig 中做同样的事情?
您将需要使用twig 扩展程序,它将创建一个自定义函数供您在 twig 中使用。
例如:
/**
* Convert camel case to a capitalised human readable string.
*
* @param $camelCase string
* @return string
*/
public function camelCaseToString($camelCase)
{
return preg_replace("/([A-Z])/", " $1", ucfirst($camelCase));
}
这应该将thisIsAnExample
转换为This Is An Example
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.