Forum Moderators: coopster

Message Too Old, No Replies

Need help with preg match syntax

         

wsmeyer

3:02 am on Feb 14, 2007 (gmt 0)

10+ Year Member



I am trying to strip info from a portion of an email that is always in this format:

-----------------------

Ship To:

Customer Name
123 Main St
Anytown
CA
12345
US

Number of Packages

----------------------

What I have so far:

preg_match('/Ship To:+([^Number]+)/s', $page_contents, $match_array);
$ShipTo = $match_array[1];

works but on the off chance someone uses something like

123 Main st, Number 2

In their address it will stop prematurely, second issue is that I would like to keep the line breaks in the variable, as it stands now they are being replaced with spaces.

William.

dreamcatcher

9:00 am on Feb 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi wsmeyer,

Instead of using regex, how about using either file [uk2.php.net] or file_get_contents [uk2.php.net] functions? The first would probably be best as this reads the contents of your file into an array. You can then just access the data you need.

dc