我希望通過大量文本輸出進行加密并將 css 樣式插入文本。列每次都保持不變,但是我試圖收集的最初開始的編號從 1-50 不等,有時是 1-13,有時都是 1-50。
我已經嘗試了每個數字的替換方法,但我無法替換每個變數以使其易于解釋以進行集成。
我的代碼是:
$text = $page->getText();
$search = array('1. ');
$replace = array('<br />1. ');
$result = str_replace($search, $replace, $text);
echo $result;
格式化前的輸出是:
描述 數量 單位價格 TAX RCV DEPREC。ACV 1. 取下 3 個標簽 - 25 年。- 復合瓦屋頂 - 21.25 SQ 52.83 0.00 1,122.64 (0.00) 1,122.64 包括 毛氈 2. 3 片 - 25 年。- 復合瓦屋頂 - 包括。氈24.67 SQ 186.84 199.43 4,808.77(0.00)4,808.77 3. R&R滴落邊緣196.95 LF 2.33 16.27 475.16(0.00)475.16 4.瀝青起動機 - 通用初級課程100.58 LF 1.31 3.67 135.43(0.00)135.43 5.冰&水屏障118.94 SF 1.15 4.34 141.12 (0.00) 141.12 6. R&R 屋頂通風口 - 龜型 - 金屬 5.00 EA 51.09 6.55 262.00 (0.00) 262.00 7. R&R Flashing - 管千斤頂 ..85310R 10 3.06" R&R 0.840" 10 EA 3.06" 0.840R 10 EA 36.80 3.40 77.00 (0.00) 77.00 9. R&R Ridge cap - 復合帶狀皰疹 77.58 LF 4.67 7.04 369.33 (0.00) 369.33 10. 數字衛星系統 - 分離和 EA 100 重置 1.
我正在尋找將其轉換為每行(1-~50)的如下表格:
<table>
<tr>
<th>DESCRIPTION</th>
<th>QUANTITY</th>
<th>UNIT PRICE</th>
<th>TAX</th>
<th>RCV</th>
<th>DEPREC.</th>
<th>ACV</th>
</tr>
<tr>
<td>1. Remove 3 tab - 25 yr. - composition shingle roofing - incl. felt</td>
<td>21.25 SQ </td>
<td>52.83</td>
<td>0.00</td>
<td>1,122.64</td>
<td>(0.00)</td>
<td>1,122.64</td>
</tr>
</table>
有沒有辦法可以使用 javascript 或在替換中替換來完成此操作?
uj5u.com熱心網友回復:
如果此資料是真實世界的樣本,您應該能夠吐出一個或多個數字,后跟一個句點,兩邊用空格包圍。這至少會給你你的個人線路。
<?php
$text = <<<TAG
DESCRIPTION QUANTITY UNIT PRICE TAX RCV DEPREC. ACV 1. Remove 3 tab - 25 yr. - composition shingle roofing - 21.25 SQ 52.83 0.00 1,122.64 (0.00) 1,122.64 incl. felt 2. 3 tab - 25 yr. - composition shingle roofing - incl. felt 24.67 SQ 186.84 199.43 4,808.77 (0.00) 4,808.77 3. R&R Drip edge 196.95 LF 2.33 16.27 475.16 (0.00) 475.16 4. Asphalt starter - universal starter course 100.58 LF 1.31 3.67 135.43 (0.00) 135.43 5. Ice & water barrier 118.94 SF 1.15 4.34 141.12 (0.00) 141.12 6. R&R Roof vent - turtle type - Metal 5.00 EA 51.09 6.55 262.00 (0.00) 262.00 7. R&R Flashing - pipe jack 3.00 EA 38.63 2.95 118.84 (0.00) 118.84 8. R&R Rain cap - 6" 2.00 EA 36.80 3.40 77.00 (0.00) 77.00 9. R&R Ridge cap - composition shingles 77.58 LF 4.67 7.04 369.33 (0.00) 369.33 10. Digital satellite system - Detach & reset 1.00 EA 31.40 0.00 31.40 (0.00) 31.40 11. Digital satellite system - alignment and calibration 1.00 EA 94.19 0.00 94.19 (0.00) 94.19 only 12. R&R Flashing - pipe jack - split boot 1.00 EA 76.00 3.76 79.76 (0.00) 79.76 13. R&R Gutter / downspout - aluminum - up to 5" 152.58 LF 7.13 49.56 1,137.45 (0.00) 1,137.45
TAG;
var_dump(explode(PHP_EOL, preg_replace('/\s (\d \.)\s /', PHP_EOL . '$1 ', $text)));
這輸出:
array (
0 => 'DESCRIPTION QUANTITY UNIT PRICE TAX RCV DEPREC. ACV',
1 => '1. Remove 3 tab - 25 yr. - composition shingle roofing - 21.25 SQ 52.83 0.00 1,122.64 (0.00) 1,122.64 incl. felt',
2 => '2. 3 tab - 25 yr. - composition shingle roofing - incl. felt 24.67 SQ 186.84 199.43 4,808.77 (0.00) 4,808.77',
3 => '3. R&R Drip edge 196.95 LF 2.33 16.27 475.16 (0.00) 475.16',
4 => '4. Asphalt starter - universal starter course 100.58 LF 1.31 3.67 135.43 (0.00) 135.43',
5 => '5. Ice & water barrier 118.94 SF 1.15 4.34 141.12 (0.00) 141.12',
6 => '6. R&R Roof vent - turtle type - Metal 5.00 EA 51.09 6.55 262.00 (0.00) 262.00',
7 => '7. R&R Flashing - pipe jack 3.00 EA 38.63 2.95 118.84 (0.00) 118.84',
8 => '8. R&R Rain cap - 6" 2.00 EA 36.80 3.40 77.00 (0.00) 77.00',
9 => '9. R&R Ridge cap - composition shingles 77.58 LF 4.67 7.04 369.33 (0.00) 369.33',
10 => '10. Digital satellite system - Detach & reset 1.00 EA 31.40 0.00 31.40 (0.00) 31.40',
11 => '11. Digital satellite system - alignment and calibration 1.00 EA 94.19 0.00 94.19 (0.00) 94.19 only',
12 => '12. R&R Flashing - pipe jack - split boot 1.00 EA 76.00 3.76 79.76 (0.00) 79.76',
13 => '13. R&R Gutter / downspout - aluminum - up to 5" 152.58 LF 7.13 49.56 1,137.45 (0.00) 1,137.45',
)
演示在這里:https : //3v4l.org/n01E5
從那里,您將需要執行一些額外的規則,我認為您可能最終會撰寫決議器,除非您的資料每次都完全匹配。
您可能需要考慮使用格式提取文本,或者可能嘗試將其提取為表格資料。不幸的是,這兩個例子都是用 C# 撰寫的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/363315.html
標籤:javascript php html
上一篇:回傳輸入值
下一篇:將vuejs資料附加到div
