Thanks. that worked perfectly.
Kathy A Wright | Keane Inc. | Suite:
Outside: 617-517-1706 | E-mail: [EMAIL PROTECTED]
[ Mailing: 100 City Sq. Charlestown, MA 02129 USA ]
Martin Norland <[EMAIL PROTECTED]>
03/02/2005 03:39 PM
Please respond to php-db
To: [email protected]
cc:
Subject: Re: [PHP-DB] preg_match html tags
[EMAIL PROTECTED] wrote:
> I am trying to get a string of text in an html page using preg_match.
The
> text starts after the Purpose</p> tag and ends before the next </p> tag.
> When using preg_match it captures the first </p> tag on the page and not
> the one after my starting point.
>
> Here is my starting point:
> preg_match("/Purpose\<\/p\>/i", $fpRead, $matches_new)
>
> Here is my ending point:
> preg_match("/<(\/p)>/s", $fpRead,$m_new);
> I have also tried using offset
> preg_match("/<(\/p)>/s", $fpRead,$m_new, $matches_new[0]);
>
> Does anyone have any suggestions? I also don't know if my syntax is
> correct for the string </p>...
>
> Thanks
> Any help will be appreciated.
>
> Kathy
>
>
> Kathy A Wright | Keane Inc. | Suite:
> Outside: 617-517-1706 | E-mail: [EMAIL PROTECTED]
> [ Mailing: 100 City Sq. Charlestown, MA 02129 USA ]
You want to match the second expression starting after that Purpose</p>.
Use:
preg_match("/<(\/p)>/s", $matches_new[0], $m_new);
.. check the documentation on php.net for that function, you don't pass
it an offset - it takes an optional flag to return the offset along with
the matches. You may have been thinking of:
strpos($haystack, $needle, [$offset])
- which is what I would recommend using for the first part (since you
want the first occurrence), then using that with substr() to get the
first occurrence of a closing </p> to get the string you want.
[ warning - wholly untested code :) ]
$start = strpos($fpRead, "Purpose</p>");
$end = strpos($fpRead, "</p>", $start);
// make what we're doing clearer for the mailing list
// also helps in case offsets are a little strange.
$length = $end - $start;
$what_i_want = $substr($fpRead($start,$length));
cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International
Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php