dongying3830 2010-10-24 22:47
浏览 55

php,preg_match,regex,提取特定文本

I have a very big .txt file with our clients order and I need to move it in a mysql database . However I don't know what kind of regex to use as the information is not very different .

-----------------------
4046904


KKKKKKKKKKK
Laura Meyer
MassMutual Life Insurance
153 Vadnais Street

Chicopee, MA 01020
US
413-744-5452
lmeyer@massmutual.co...


KKKKKKKKKKK
373074210772222 02/12 6213 NA
-----------------------
4046907


KKKKKKKKKKK
Venkat Talladivedula

6105 West 68th Street

Tulsa, OK 74131
US
9184472611
venkat.talladivedula...


KKKKKKKKKKK
373022121440000 06/11 9344 NA
-----------------------

I tried something but I couldn't even extract the name ... here is a sample of my effort with no success


$htmlContent = file_get_contents("orders.txt");

//print_r($htmlContent);

$pattern = "/KKKKKKKKKKK(.*)
/s";
preg_match_all($pattern, $htmlContent, $matches);
print_r($matches);
$name = $matches[1][0];
echo $name;

  • 写回答

4条回答 默认 最新

  • doutonghang2761 2010-10-24 22:57
    关注

    You may want to avoid regexes for something like this. Since the data is clearly organized by line, you could repeatedly read lines with fgets() and parse the data that way.

    评论

报告相同问题?