我有一个菜单,我正在加载到模板上。唯一的问题是他们希望它看起来的方式是拥有第一个数字正常字体大小(比方说12px)和最后一个数字更小(比如9px)
有没有办法自动查找最后2个字符并更改字体大小?因为菜单不同。它可能是7.99,也可能是12.99。我可以很容易地打电话说第3和第4个角色会改变,但它是如此变化。感谢您在正确的方向上提供任何帮助。
$spaces = str_replace(" ", "", $this->orderData->menu1);
$checkPrice =preg_replace('/^(\d{3})(\d{3})$/', '$1.$2', $spaces);
答案 0 :(得分:0)
是, 我假设12.99是一个价格,你希望.99更小。 我将为此示例注入内联样式,但它也可以是类名...
// Lets assume the string is this
$string = "Hello, the price of pie is 12.99 today but now the pie is only 1.99 and not .99p";
// Let's replace the pence with any number between 1.00 and 9999.99
$string = preg_replace("/([0-9]{1,4})\.([0-9]{2})/is","\$1.<span style='font-size:9px'>\$2</span>",$string);
// If you wanted the price of ".99" too (meaning there are no pounds)
// then this would work
$string = preg_replace("/([0-9]{0,4})\.([0-9]{2})/is","\$1.<span style='font-size:9px'>\$2</span>",$string);