2012-04-11 58 views
0

我有一個變量數組包含這些名稱;PHP回聲有限的輸出字符串?

// Listing ENTITIES 
$entitiesTable = array(
    1 => "user", 
    2 => "group", 
    3 => "customer", 
    4 => "supplier", 
    5 => "terminal", 
    6 => "order", 
    7 => "invoice", 
    8 => "invoice detail", 
    9 => "invoice offer", 
    10 => "invoice offer detail", 
    11 => "quotation", 
    12 => "quotation detail", 
    13 => "quotation offer", 
    14 => "quotation offer detail", 
    15 => "purchase order", 
    16 => "purchase order detail", 
    17 => "purchase order request", 
    18 => "purchase order request detail", 
    19 => "sales order", 
    20 => "sales order detail", 
    21 => "delivery order", 
    22 => "delivery order detail", 
    23 => "sales return", 
    24 => "sales return detail", 
    25 => "purchase return", 
    26 => "purchase return detail", 
    27 => "item", 
    28 => "category", 
    29 => "unit measurement", 
    30 => "last activity", 
    31 => "rack", 
    32 => "alert", 
    33 => "filter", 
    34 => "prefix code", 
    35 => "system", 
    36 => "company profile" 
); 

而在我的php身體的中間,我創建了For Loops。 迭代該數組,然後呼應 em出來。

foreach ($entitiesTable as $singleEntity){ 
if(preg_match($regexUsed, $singleEntity)){ 
    $pluralEntity = preg_replace($regexUsed, 'ies', $singleEntity); 
} else { 
    $pluralEntity = $singleEntity . 's';  
} 

// Replacing spaces with a dash character and capitalize the first word 
$pluralEntityWOSpace = ucwords($pluralEntity); 
$pluralEntityWOSpace = str_ireplace(" ","" , $pluralEntityWOSpace); 

$pluralEntityWDash = str_ireplace(" ","-" , $pluralEntity); 

$singleEntityWOSpace = ucwords($singleEntity); 
$singleEntityWOSpace = str_ireplace(" ","" , $singleEntityWOSpace); 

echo $singleEntityWOSpace . '<br/>'; 
} 

不知怎的,我才意識到它的權利,即我得到什麼不是的全名,因爲它是從早期的數組中列出。相反,我現在得到的只是這些名字中的一小部分。看! 下面是我得到的輸出名稱:

User 
Group 
Customer 
Supplier 
Terminal 
Order 
Invoice 
InvoiceDetail 
InvoiceOffer 
InvoiceOfferDetail 
Quotation 
QuotationDetail 
QuotationOffer 
QuotationOfferDetail 
PurchaseOrder 
PurchaseOrderDetail 
PurchaseOrderRequest 
PurchaseOrderRequestDetail 
SalesOrder 
SalesOrderDetail 
DeliveryOrder 
DeliveryOrderDetail 
SalesReturn 
SalesReturnDetail 
PurchaseReturn 
PurchaseReturnDetail 
Item 
Category 
UnitMeasurement 
LastActivit 

我試着寫FLUSH()PHP腳本的結束,這些名稱的輸出都OK。但後來它給我另一個錯誤,因爲我使用苗條框架。 是否有另一種替代方法,而不是使用FLUSH()

+1

可能有些奇特的輸出緩衝。在腳本的末尾寫ob_flush()以查看是否有效。 – 2012-04-11 07:37:34

+0

雅我已經試過了,但似乎它是Slim框架的限制,當我們在處理ECHO時,它尚未執行Slim() - > run()方法。 我的迴應是有限的。 – gumuruh 2012-04-17 09:03:24

回答

0

這樣做的真正的快速的答案是,通過對矯正的php.ini文件;

output_buffering = 4096 
implicit_flush = Off 

然後重新啓動APache服務器。我不知道爲什麼,但它的工作原理。

0

我認爲你正在尋找有些所謂CamelCase, 這裏是首字母大寫功能的字符串:

function to_camel_case($str, $capitalise_first_char = false) { 
    if($capitalise_first_char) { 
    $str[0] = strtoupper($str[0]); 
    } 
    $func = create_function('$c', 'return strtoupper($c[1]);'); 
    return preg_replace_callback('/_([a-z])/', $func, $str); 
} 

摘自:http://www.paulferrett.com/2009/php-camel-case-functions/

+0

感謝駱駝案件@丹李......但問題是「回聲過程」。它沒有正確迴應所有的文字。 – gumuruh 2012-04-17 09:02:40