2014-07-16 4 views
0

HTML 파일을 풀다운하기 위해 CURL 명령을 사용하는 스크립트를 작성했습니다. HTML 파일을 가져 오면 코드를 추출합니다. 코드는 이와 같이 형식을 지정할 수 있습니다. PHP 코드를 작성하고 HTML 파일을 스캔하여

A = Letters | 0 = numbers 

A0000-00000-00000-00000-00000 

는이 코드

$searchfor = "/The software code:&nbsp;</STRONG>/"; 
$pattern = preg_quote($searchfor, '/'); 
$pattern = "/^.*$pattern.*\$/m"; 

$number = preg_grep($searchfor, $result); 
foreach($number as $name) { 
echo $name; 
} 

를 사용하지만, 아무 결과를 얻지 없습니다 시도했다. 매번 소프트웨어 코드가 페이지의 78 행에 나옵니다. 그래서 내가 추출하면 원치 않는 데이터를 제거 할 수 있습니다.

답변

0
<?php 

$string = "asdfasrgarehdtehrjxx1234-12345-12345-12345-12345dfgfgnhfjnghfdj"; 
$matches = array(); 

preg_match("([A-Za-z][0-9]{4}-[0-9]{5}-[0-9]{5}-[0-9]{5}-[0-9]{5})", $string, $matches); 

var_dump($matches); 

http://runnable.com/U8bi7kzjBq4I839h/php-find-string-with-regex

+1

귀하의 빠른 답장을 보내 주셔서 감사합니다! –

0
<?php 

$subject = "fs dfasfA0000-00000-00000-00000-00000fsfsf sad fsafC4533-23423-23424-23424-14144fsadf rwer wqF0094-13133-23412-23566-93946sdfshdfh"; 
$pattern = '/[A-Z]\d{4}-\d{5}-\d{5}-\d{5}-\d{5}/'; 
preg_match_all($pattern, $subject, $matches); 
print_r($matches[0]); 

?> 

출력 :

Array ( 
    [0] => A0000-00000-00000-00000-00000 
    [1] => C4533-23423-23424-23424-14144 
    [2] => F0094-13133-23412-23566-93946 
) 
관련 문제