Re: RegEx
| From: | Ernest E Vogelsinger | Date: | Mon, 26 May 2003 07:55:10 +0000 |
| Subject: | Re: RegEx | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148958@lists.php.net to get a copy of this message | ||
At 02:05 26.05.2003, Brian V Bonini said:
--------------------[snip]--------------------
>Trying to pull data from a remote location and extract a certain section
>(and yes I have permission). Can not seem to get this to work:
>
>$siteurl = "http://domain.com";
>$string = file($siteurl);
>$matches = array();
>preg_match_all('|\<\!--***** BEGIN HOME PAGE CONTENT *****
>--\>(.*?)\<\!--***** END HOME PAGE CONTENT ***** --\>|is',$string,
>$matches);
>//see what we have
>echo '<pre>';
>print_r($matches);
>echo '</pre>';
--------------------[snip]--------------------
2 problems with your code:
1) file() returns an array, not a single string. Use
$string = join('', file($siteurl));
2) asterisks are special characters within a regular expression, you need
to escape them. Try this regex:
$re = '|<!--\*{5,5} BEGIN HOME PAGE CONTENT \*{5,5} -->' .
'(.*?)' .
'<!--\*{5,5} END HOME PAGE CONTENT \*{5,5} -->|is';
You don't need to escape the other characters.
(Tested and worked).
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/