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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.