我一直在嘗試編寫一個正則表達式,它將在分號(';')之後刪除空格,當它位於打開和關閉大括號('{',' }「)。我已經到了某個地方,但一直未能完成。在這裏我已經有了:PHP正則表達式:如何在兩個字符串之間劃分空白
<?php
$output = '@import url("/home/style/nav.css");
body{color:#777;
background:#222 url("/home/style/nav.css") top center no-repeat;
line-height:23px;
font-family:Arial,Times,serif;
font-size:13px}'
$output = preg_replace("#({.*;) \s* (.*[^;]})#x", "$1$2", $output);
?>
的的$輸出應該如下。另外請注意,字符串中的第一個分號仍然跟着空格,因爲它應該是。
<?php
$output = '@import url("/home/style/nav.css");
body{color:#777;background:#222 url("/home/style/nav.css") top center no-repeat;line-height:23px;font-family:Arial,Times,serif;font-size:13px}';
?>
謝謝!提前給任何願意給它一個機會的人。
非常感謝你,這正是我所需要的。 – roydukkey 2010-03-20 03:04:17
可能會考慮放棄;)... – pinaki 2010-04-05 14:39:04