[PHP-DB] Re: preg_match html tags
Do it with one preg_match operation, like so: preg_match("/(?<=Purpose).+?(?=<\/p>)/", $fpRead, $matches_new); Your string will reside in $matches_new[0]. EXAMPLE: $fpRead = "blah blah PurposeThis is the string you are after blah blah blah blah blah"; preg_match("/(?<=Purpose).+?(?=<\/p>)/", $fpRead, $matches_new); print_r($matches_new); EXPLANATION: (?<=Purpose) - backward looking assertion. Read as: "Expression immediately following must match only strings with "Purpose" immediately before." .+? - any character, 1 or more, ungreedy. Ungreedy because otherwise it will match right up to the last possible place it can. You want it to match up until the next '', not the last ''. (?=<\/p>) - forward looking assertion. Read as: "Expression immediately prior must match only strings with "" immediately after." Hope this helps. Laurence "Kathy A Wright" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I am trying to get a string of text in an html page using preg_match. The > text starts after the Purpose tag and ends before the next tag. > When using preg_match it captures the first 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 ... > > 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 ] > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: (preg_match ?
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > $search = "TheName" > $data = "TheName,TheAddress,ThePhone" > > if (preg_match('"/\b'.$search.'\b/i"', $data)) > { > echo "True"; > } > else > { > echo "False"; > } > I am trying to see if the search name matches exactly a name in the $data. In that case, may I suggest an alternative method? $arr=explode(",",lower($data)); if(in_array(lower($search),$arr))) ... (If you want to use the preg_*: take out the double quotes in your regex, which do not appear to be delimiting the substrings within variable $data.) -- CC -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Re: (preg_match ?
This works only if the list is space delimited because of the \b: $search = "TheName"; $data = "TheName TheAddress ThePhone"; if (preg_match("/\b$search\b/i", $data)) { echo "True"; } else { echo "False"; } However as your list is now this works: $search = "TheName"; $data = "TheName,TheAddress,ThePhone"; if (preg_match("/$search/i", $data)) { echo "True"; } else { echo "False"; } -- phill <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > What's wrong with this use of preg_match? > > $search = "TheName" > $data = "TheName,TheAddress,ThePhone" > > if (preg_match('"/\b'.$search.'\b/i"', $data)) > { > echo "True"; > } > else > { > echo "False"; > } > I am trying to see if the search name matches exactly a name in the $data. > Thanks > Dave -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]