我正试图从1699.20
中抓取价格1'699.200
。
我如何通过regex exp做到这一点?
Reservation source: Booking.com reservation #591064783
The following information was provided by Booking.com at the time the reservation was created:
*** Reservation information ***
Reservation made on: 2015-11-08 at 23:54:52
Currency: EUR
Total reservation amount: 1'699.200
Total reservation commission amount: 254.880
*** Customer information ***
Name: Daniele
Email: 677114@guest.booking.com
Address:
Zip / Post code:
City: .
Country: Switzerland
Company:
Phone: +41761
Remarks: Hello, we might be 9 friends, and we can bring our own mattress would it be a problem? If it is, then we will be 8.
*** Room guest information ***
Room arrival date: 2015-12-29
Room departure date: 2016-01-02
Check-in: 2015-12-29
Check-out: 2016-01-02
Guest name: Daniele
Number of guests: 8
Smoking preference: Non-smoking
Remarks:
*** Room/facilities information ***
Room facilities: Tea/Coffee maker, Shower, Hairdryer, Iron, Refrigerator, Desk, Ironing facilities, Sitting area, Fan, Toilet, Microwave, Washing machine, Bathroom, Heating, Kitchen, Flat-screen TV, Sofa, Hardwood/Parquet floors, Dining area, Electric kettle, Kitchenware, Wardrobe/Closet, Oven, Stovetop, Cleaning products, City view, Towels, Linens, Dining table, Private apartment in building, Clothes rack
Room information: No meal is included in this room rate. Children and Extra Bed Policy: All children are welcome. One child under 3 years is charged EUR 10 per night in a crib. Any additional children under 4 years are charged EUR 10 per night for extra beds. The maximum number of extra beds/cribs in a room is 1. Deposit Policy: 20 percent of the total amount may be charged anytime after booking. Cancellation Policy: Please note, if canceled or modified, 100 percent of the total price of the reservation will be charged.
Room extra information: This apartment has a washing machine, seating area and oven.
*** Room pricing information ***
Currency: EUR
Total price: 1'699.200
Commission: 254.880
Nightly prices:
2015-12-29: 424.000 (rate: 4103701 "Standard Rate")
2015-12-30: 424.000 (rate: 4103701 "Standard Rate")
2015-12-31: 424.000 (rate: 4103701 "Standard Rate")
2016-01-01: 427.200 (rate: 4103701 "Standard Rate")
这是我尝试过的,https://regex101.com/r/aE6vK0/1,但不是这样。
答案 0 :(得分:1)
我不是PHP大师,但已经给出的评论似乎是一个很好的方向。对于每个模板,您只需针对每一行运行以下正则表达式:
Total reservation amount:\s(.*)
我将假设上面的匹配将存储到名为$num
的PHP变量中。您可以将其转换为double
,然后根据需要使用它,例如
$num = 1'699.200;
$num = str_replace("'", "", $num);
$double_val = doubleval($num)
由于您正在抓取的模板本身可能都是由(确定性)计算机程序生成的,因此您不必处理随机格式。相反,应该有一组格式,您可以通过查看许多模板来预测。