我有数组变量,包含这些名称;
// 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循环。 迭代数组,然后回显 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
我尝试在 php脚本的末尾写 FLUSH(),这些名称的输出正常。但是它给了我另一个错误,因为我正在使用 Slim Framework 。 是否有其他替代方式而不是使用 FLUSH()?
答案 0 :(得分: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/
答案 1 :(得分:0)
真正的快速答案是,通过修改php.ini文件;
output_buffering = 4096
implicit_flush = Off
然后重新启动APache服务器。我不知道为什么但它有效。