simple_html_don problem

Discussion in 'PHP' started by scottlpool2003, Feb 14, 2011.

  1. #1
    Hi guys

    Having a couple of issues with the simple_html_don function....

    I'm trying to grab some content from my site to store into a db.

    I'm trying to grab something like:

    <div id="items">

    <a href="item/item1.php">item 1</a><br>
    <a href="item/item2.php">item 2</a><br>


    Here's my code:

    <?php
    
    //echo variable
    
    { 
    	$url = 'items.php';
    
      	require_once 'simple_html_dom.php';  
    
    
    		//define url
    		$html = file_get_html("$url");
    	    //get elements
    		$link = $html->getElementsByTagName('div[id=items]');
    
    
    		//get elements
    		foreach($link->find('a') as $element) 
    
    
    		//split links into title/url
    			
    		//output
            echo $element->href . '<br><br>';
    
    }  
    ?>
    
    PHP:
    What I'd like to do is split:
    <a href="item/item1.php">item 1</a>

    into:

    item
    item1.php

    and then enter into the db as:

    id
    title
    url

    Any help is appreciated, been trying for days now.

    Thanks


    Forgot to add:

    The way it works at the moment is that it grabs all content between the <a> tags and outputs them as:

    item/item1.php
    item/item2.php
    item/item3.php

    If I view the source it doesn't display the code but I've worked out that it's all one array.

    I'm no good with arrays or exploding so any help i welcomed

    Thanks guys

    Scott.
     
    Last edited: Feb 14, 2011
    scottlpool2003, Feb 14, 2011 IP