Jump to content

how do i skip the 1st instance of a tag in the following code but pick up the2nd


Recommended Posts

$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?

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

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.

 

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]);}

 

?>

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]);}

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);

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

 

where is my other  jpg  number

Array

(

    [0] => Array

        (

            [0] =>  Array

        (

            [0] => 1591167264

        )

 

)

 

it does not show both values on the page just one

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

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.