Re: [PHP] HTML Parse Issue
[EMAIL PROTECTED] wrote: I am having a issue parsing an html file. I want to pull all the data between two html tags. Problem I am having is that no matter what I try I can pull either tag or both but not the data in between. div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one function datamatch($document) { preg_match_all('/div class=record [^]*(.*)/\/div class=record [^]*/i',$document,$elements); $match = implode(\r\n,$elements[0]); return $match; } This should return the following div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one plaintext?php $data = ' div class=record id=onediv class=rideonh2spanWelcome to Rideon #1/span/h2/div/div div class=record id=twodiv class=rideonh2spanWelcome to Rideon #2/span/h2/div/div div class=record id=threediv class=rideonh2spanWelcome to Rideon #3/span/h2/div/div div class=record id=fourdiv class=rideonh2spanWelcome to Rideon #4/span/h2/div/div '; if ( preg_match_all('!div class=record id=([^]+)div class=rideonh2span([^]+)/span/h2/div/div!', $data, $matches, PREG_SET_ORDER) ) { print_r($matches); } else { echo 'Could not match anything.'; } -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] HTML Parse Issue
Jim Lucas wrote: [EMAIL PROTECTED] wrote: I am having a issue parsing an html file. I want to pull all the data between two html tags. Problem I am having is that no matter what I try I can pull either tag or both but not the data in between. div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one function datamatch($document) { preg_match_all('/div class=record [^]*(.*)/\/div class=record [^]*/i',$document,$elements); $match = implode(\r\n,$elements[0]); return $match; } This should return the following div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one plaintext?php $data = ' div class=record id=onediv class=rideonh2spanWelcome to Rideon #1/span/h2/div/div div class=record id=twodiv class=rideonh2spanWelcome to Rideon #2/span/h2/div/div div class=record id=threediv class=rideonh2spanWelcome to Rideon #3/span/h2/div/div div class=record id=fourdiv class=rideonh2spanWelcome to Rideon #4/span/h2/div/div '; if ( preg_match_all('!div class=record id=([^]+)div class=rideonh2span([^]+)/span/h2/div/div!', $data, $matches, PREG_SET_ORDER) ) { print_r($matches); } else { echo 'Could not match anything.'; } I just realized a problem with this code. You have tabs/spaces/new lines between your different tags, so my regx needs a little modification Try this instead: plaintext?php $data = ' div class=record id=one div class=rideon h2spanWelcome to Rideon #1/span/h2 /div /div div class=record id=two div class=rideon h2spanWelcome to Rideon #2/span/h2 /div /div div class=record id=three div class=rideon h2spanWelcome to Rideon #3/span/h2 /div /div div class=record id=four div class=rideon h2spanWelcome to Rideon #4/span/h2 /div /div '; if ( preg_match_all('!div class=record id=([^]+)\s*div class=rideon\s*h2\s*span([^]+)/span\s*/h2\s*/div\s*/div!', $data, $matches, PREG_SET_ORDER) ) { print_r($matches); } else { echo 'Could not match anything.'; } -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] HTML Parse Issue
I am having a issue parsing an html file. I want to pull all the data between two html tags. Problem I am having is that no matter what I try I can pull either tag or both but not the data in between. div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one function datamatch($document) { preg_match_all('/div class=record [^]*(.*)/\/div class=record [^]*/i',$document,$elements); $match = implode(\r\n,$elements[0]); return $match; } This should return the following div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one
Re: [PHP] HTML Parse Issue
[EMAIL PROTECTED] wrote: I am having a issue parsing an html file. I want to pull all the data between two html tags. Problem I am having is that no matter what I try I can pull either tag or both but not the data in between. div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one function datamatch($document) { preg_match_all('/div class=record [^]*(.*)/\/div class=record [^]*/i',$document,$elements); $match = implode(\r\n,$elements[0]); return $match; } This should return the following div class=record id=one div class=rideon h2 spanWelcome to Rideon/span /h2 /div /div /div class=record id=one You may want to try escaping your quotations. That could cause some issues. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php