PHP以有限的输出回响长串?

问题描述:

I have a variable of array containing such as these names;

// 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"
); 

And at the middle of my php body, i create For Loops. Iterating the array, and then echoing em out.

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/>';
}

Somehow, I just realized it right now, that What i obtained is NOT A WHOLE NAME as it's listed earlier from the array. Instead, What I got now is just a small piece of those names. Look! Here are the output names I obtained:

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

I tried to write FLUSH() at the end of my php script, and the output of those names are OK. But then it gives me another error, since I'm using Slim Framework. Is there another alternatives way rather than using FLUSH()?

The real quick answer for this is, by modifing the php.ini file;

output_buffering = 4096
implicit_flush = Off

And then restarting the APache server. I dunno why but it works.

I think you're looking for somewhat called CamelCase, here is a string to camelcase function:

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);
}

Taken from: http://www.paulferrett.com/2009/php-camel-case-functions/