So ive parsed a page for a LINK... lets say.. the link is...

www.mysite.com/yabadaba1304993

now I want to further parse that link by grabbing only the number 1304993

anyone ever successfully done this?? heres the find line I use. .

$item['link'] = $article->find('a',0)->href;

where would/could you code in ... to grab the last 7 charactors from the right on that link ( and later each links)??

possible? lemme know if youve you successfully done this before. thx

( its easy "after" its sent to mysql.. you can do it then.. but I wanted to know if its possible before being sent to mysql insert. )

    Its simple with [man]substr[/man] and [man]strlen[/man]:

    $link = 'www.mysite.com/yabadaba1204993';
    $last7 = substr($link,-7);
    
    echo "The last 7 characters of the string are: $last7";

      yeah but heres where im a lil confused and I bet alot of others new to simple html DOM.

      this below..... " on the fly"...

      $item['link'] = $article->find('a',0)->href;
      

      returns what?? to place below..

      Like?.. $link= '$item['link']"; ????

      or $link='what exactly goes here?';

      $link = 'www.mysite.com/yabadaba1204993 NEEDS to go here but on the fly is it.. $item['link']'; //??????????
      $last7 = substr($link,-7);
      
      echo "The last 7 characters of the string are: $last7"; 
      

      or even

      $last7 = substr($link,-7);  //  could it be $last7 = substr($item['link'],-7);
      

      heres my code..

      <?php
      
      include('simple_html_dom.php');
      
      // Create DOM from URL or file
      $html = file_get_html('http://mysite.com/yabadabaexample.html');
      foreach($html->find('table.results') as $article) {
          $item['image']     = $article->find('img[class=thumbnail]',0)->src;
          $item['title']    = $article->find('strong',0)->plaintext;
          $item['details'] = $article->find('div[style=margin-top:5px]',0)->plaintext;
          $item['price'] = $article->find('td[id=price]',0)->plaintext;
          $item['timestamp'] = $article->find('td[width=13%]',0)->plaintext;
          $item['link'] = $article->find('a',0)->href;
          $item['number'] = $article->find('a',0)->href;
      
      
      //  $item['link'] = $article->find('a',0)->href;
      
      //pulls http://mysite.com/yabadabaexample1448126
      
      //?? $last7 = substr($item['link'],-7);
      
      //or could this work??  
      
      //$item['link'] = $article->find(('a',0),-7)->href;  ????
      
      
      
      $articles[] = $item;
      }
      print_r($articles); 
      
      
      
      ?>
      

      the above you gave me is simple part, its how to actually call the link on the fly Im looking for. Dont get me wrong! thanks for reply.. its just need a little more than that.

        Your question has nothing to do with DOM and everything to do with basic PHP syntax. If $item['link'] contains the string you're wanting, then sure, use it instead of "$link".

          I just wanted to know if IN DOM.. you could add this to this.. and it would work.

          substr($item['link'],-7); this... into below line.. for on the fly.

          $item['link'] = $article->find('a',0)->href;
          
          //like?
          
          $item['link'] = $article->find(('a',0)$item['link'],-7)->href;
           

          just wondered if anyone has done it successfully.

          guess you cant if $item['link'] isnt even created yet.. man am I DOMMY! lol..

          ok I'll work with what was suggested above. Im using arrays and I have no idea how to construct it using.. the above example..

            HELL YA!! thanks guys.. next time i wont OVER THINK and just TRY! works..

            <?php
            
            include('simple_html_dom.php');
            
            // Create DOM from URL or file
            $html = file_get_html('http://mysite.com/linkspage.html');
            foreach($html->find('table.results') as $article) {
                $item['image']     = $article->find('img[class=thumbnail]',0)->src;
                $item['title']    = $article->find('strong',0)->plaintext;
                $item['details'] = $article->find('div[style=margin-top:5px]',0)->plaintext;
                $item['price'] = $article->find('td[id=price]',0)->plaintext;
                $item['timestamp'] = $article->find('td[width=13%]',0)->plaintext;
                $item['link'] = $article->find('a',0)->href;
                $item['number'] = $article->find('a',0)->href;
            
            $item['link2'] = $article->$last7 = substr($item['link'],-9);
            
            
            
            $articles[] = $item;
            }
            print_r($articles); 
            
            
            
            ?>
            

            thanks for the late reply below.. i got it workin!

              0o0o0;11006397 wrote:

              I just wanted to know if IN DOM..

              Again, your question has absolutely nothing to do with DOM. Just because you're using DOM to get the string that you're wanting to manipulate doesn't mean the basic rules of PHP syntax suddenly change.

              0o0o0;11006397 wrote:
              $item['link'] = $article->find(('a',0)$item['link'],-7)->href;
               

              For one, that's not even valid PHP syntax... this:
              code$item['link'][/code]doesn't have any meaning. Even if it did, however, what happened to the call to the [man]substr/man function?

              It's a simple matter of combining expressions. Going back to Derokorian's example, pretend it said this (obviously pseudo-code) instead:

              $variable = substr([b]expr1[/b],-7);

              Where expr1 is any expression that evaluates to a string. In other words, that could be:

              "Hello World"

              or:

              $link

              or:

              $article->find('a',0)->href

                yeah this works better.. dunno if its right but it works.

                $item['link2'] = $article = substr($item['link'],-9);

                  Write a Reply...