Jump to content

preg_match help


kev@num

Recommended Posts

Hi, I have the following code which FTPs to a site, gets the source code for a HTML file and then puts the data inbetween <TITLE> and </TITLE> into an array and this works fine:

<?php
$file = file_get_contents("ftp://user:pass@domain/public_html/index.html", "r");

if (!$file) {
    echo "<p>Unable to open remote file.\n";
    exit;
}
preg_match_all ('/<TITLE>(.*)<\/TITLE>/msU', $file, $matches, PREG_SET_ORDER);

print_r ($matches);

?>

 

Rather than finding a match for data between <TITLE> and </TITLE> however I would like it to pull back what is inbetween the following:

 

<!--START--> and <!--END-->

 

I have tried the following but it doesn't put anything into the array:

 

preg_match_all ('/<!--START-->(.*)<\/!--END-->/msU', $file, $matches, PREG_SET_ORDER);

 

This is the content of the html file if this helps:

 

<TITLE>The Title</TITLE>
<!--START--><p><strong>Some Text</strong></p>
<p><strong><img src="images/IMAG0152_2.jpg" alt="" width="200" height="100" /></strong></p>
<!--END-->

 

i can get a match on stuff between TITLEs but not START and END.. I'm not sure how to change preg_match_all to work!! i've tried loads of combinations but can't get any to work, but i'm not really sure on modifiers and patterns or escaping etc,  if anyone could help that would be great.

 

Thanks in advance :)

kev.

Link to comment
https://forums.phpfreaks.com/topic/211160-preg_match-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.