scbookz Posted August 2, 2009 Share Posted August 2, 2009 $osctag = preg_match_all('/<img src="images\/(.*).jpg/', $oscfile, $oscmatches, PREG_PATTERN_ORDER); my 1st <img src="images is the wrong one but the 2nd one on the page is right how can i skip the very 1st one everytime in this code? Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/ Share on other sites More sharing options...
Daniel0 Posted August 2, 2009 Share Posted August 2, 2009 Use the $offset argument. preg_match_all Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888749 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 maybe i didnt make myself clear when i grab from the html page there are 2 different .jpgs the 1st jpg is not the one i want in the process of reading the html page the 2nd one is what i do want my description is picking up the 1st and not the 2nd one as i like for it to do Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888752 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 ohhhhhhhh offset so far but how do i use offset lol Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888753 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 everytime i tried offset it never worked does it have to be 8 16 32 64 etc etc does it have to match some particular data for an offset? because wheni tried 2 or 3 or weird number never worked Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888755 Share on other sites More sharing options...
Daniel0 Posted August 2, 2009 Share Posted August 2, 2009 On second thought, $offset might not be so good for this. preg_match_all() will give you all the matches though, so you can just select the second one and ignore the first one. Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888757 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 what in the same h does this allmean makes no sense to me PREG_OFFSET_CAPTURE If this flag is passed, for every occurring match the appendant string offset will also be returned. Note that this changes the value of matches in an array where every element is an array consisting of the matched string at offset 0 and its string offset into subject at offset 1. Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888759 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 here is my code how do i select the 2nd one please? --------------------------------------------------- <?php $oscfile = file_get_contents("http://75:81/osc/osc/osc/catalog/product_info.php?products_id"); $osc = (get_oscdoc_title($oscfile)); $test = $osc; //function function get_oscdoc_title($oscfile){ $osctag = preg_match_all('/<img src="images\/(.*).jpg/', $oscfile, $oscmatches, PREG_PATTERN_ORDER); return($oscmatches[1][0]);} echo $test; $file = file_get_contents("http://www.bu.com/IsbnSearch.aspx?isbn={$test}"); $x = (get_doc_title($file)); echo preg_replace('/^Book -/','(10 digit isbn above) -',$x); // retrieve page title function get_doc_title($file){ $h1tags = preg_match_all('/<title>(.*)<\/title>/', $file, $matches, PREG_PATTERN_ORDER); return($matches[1][0]);} ?> Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888760 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 do i get rid of [0] in return($oscmatches[1][0]);} Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888762 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 anyone so you can just select the second one and ignore the first one. how do you ignore the 1st one in the code? Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888763 Share on other sites More sharing options...
phpSensei Posted August 2, 2009 Share Posted August 2, 2009 $matches is an ARRAY! If thats what we are talking about here cause i didnt read, just read Daniel0's post. Array( [0] => "1.jpg" [1] => "2.jpg" ) youw would be wanting the 2nd one $matches[1] Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888765 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 i understand but my function is calling the 1st part so how do i force it to see the 2nd one only and put it into my variable? Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888766 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 i have 2 jpegs <img src=x.jpg <img src=y.jpg i want the 2nd one in this function to show only function get_oscdoc_title($oscfile){ $osctag = preg_match_all('/<img src="images\/(.*).jpg/', $oscfile, $oscmatches, PREG_PATTERN_ORDER); return($oscmatches[1][0]);} Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888768 Share on other sites More sharing options...
phpSensei Posted August 2, 2009 Share Posted August 2, 2009 do print_r($oscmatches) and you'll see what i mean. its an array of matches it has found throughout the html. Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888769 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 print_r($oscmatches) gave no output but printr test gave me the very 1st isbn and printosc gave me 2 of the 1st //function function get_oscdoc_title($oscfile){ $osctag = preg_match_all('/<img src="images\/(.*).jpg/', $oscfile, $oscmatches, PREG_PATTERN_ORDER); return($oscmatches[1][0]);} //echo $test; print_r($oscmatches); Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888770 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 oh i had to move printr before the function ended thanks i see the array but now i need to know which one to call and how to do that Array ( [0] => Array ( [0] => Array ( [0] => 0324183313 ) ) 0324183313( its only showing 1 array value instead of all the values on the page for that pattern Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888772 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 where is my other jpg number Array ( [0] => Array ( [0] => Array ( [0] => 1591167264 ) ) it does not show both values on the page just one Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888774 Share on other sites More sharing options...
phpSensei Posted August 2, 2009 Share Posted August 2, 2009 your preg_match_all is wrong try preg_match_all('/<img[^>]*>/Ui',$oscfile,$oscmatches); Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888789 Share on other sites More sharing options...
scbookz Posted August 2, 2009 Author Share Posted August 2, 2009 even when i use that ist does not solve problem of skipping down to another instance i need to know how to start at a different location in a page Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-888940 Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 even when i use that ist does not solve problem of skipping down to another instance i need to know how to start at a different location in a page Preg_match_all goes through the entire match trying to find what you need, its not a matter of different locations, if it finds an img tag it stores it in its 3 argument which is an array of possible matches.. Quote Link to comment https://forums.phpfreaks.com/topic/168481-how-do-i-skip-the-1st-instance-of-a-tag-in-the-following-code-but-pick-up-the2nd/#findComment-889206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.