0

我有一个包含诸如这些名称的数组变量

// 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 循环。迭代数组,然后显它们。

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

我试图在我的php 脚本末尾写FLUSH(),并且这些名称的输出是好的。但它给了我另一个错误,因为我使用的是Slim Framework除了使用FLUSH()之外,还有其他替代方法吗?

4

2 回答 2

0

我想你正在寻找有点叫做CamelCase,这是一个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/

于 2012-04-11T07:31:59.900 回答
0

真正快速的答案是修改 php.ini 文件;

output_buffering = 4096
implicit_flush = Off

然后重启APache服务器。我不知道为什么,但它有效。

于 2012-04-17T09:07:12.593 回答