0

I'm fairly new to PHP, and i have a problem in defining a function that returns an array containing a price and description strings.

I am using the "simple html dom" php files that facilitates parsing.

The function i create requires 2 arguments : the link (from which it will grab data) and the id (used to get the proper css syntax).


This is the get_product_details.php

<? 
require_once 'simple_html_dom.php';
$priceMatchTable=('span[id=our_price_display]');
$descMatchTable=('div[id=short_description_content]');

function get_prod_details( $link , $id ) {

    global $priceMatchTable, $descMatchTable;
    $html = file_get_html($link);

    $result['price'] = $html->find($priceMatchTable[$id],0);
    $result['desc'] = $html->find($descMatchTable[$id],0);

    return $result;
}

And this is the main php:

<?php
include 'get_product_details.php';

$link = 'http://micromedia.tn/barette-memoire/1170-barette-m%C3%A9moire-1go-ddr-ii.html';
$id = 0;

$result = get_prod_details($link, $id);
echo $result['price'];



?>

Finally i get an error which tell:

find($priceMatchTable[$id],0); $result['desc'] = $html->find($descMatchTable[$id],0); return $result; }
Fatal error: Call to undefined function get_prod_details() in C:\xampp\htdocs\dom\index.php on line 8

Best regards!

Garsallah mohamed
  • 156
  • 1
  • 1
  • 10

2 Answers2

0

This may sound silliy, but is

include 'get_product_details.php';

really pointing towards "get_product_details.php"?

Disable (//) the function call in you index.php and add a simple echo to your "get_product_details.php" to see if the file gets included.

Nico Sänger
  • 138
  • 1
  • 1
  • 9
0

I think you need something like:

include '/path/from/root_to_your/directory/get_product_details.php';

If your trying this in Windows land, it will look something like:

include 'C:\Documents\something\get_product_details.php';
usumoio
  • 3,500
  • 6
  • 31
  • 57