Using External Site Information

General discussions related to php

Moderators: macek, egami, gesf

fixdreamer
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Dec 13, 2011 3:29 pm

Using External Site Information

Postby fixdreamer » Sun Jan 20, 2013 1:29 pm

Hi,

Sorry to ask, I have found a lot of mention of this subject around but I really can't get anything to work and am really struggling.

I am setting up a website which sells stock from another company. I want to use their stock levels from their website as my own. I started by using the file_get_contents command:

$suppliers_page = file_get_contents('http://www.their-website.com/product-234-page.aspx');

The output of this obviously gives me a web page, the content I am after is on line 520-1 encapsulated in theses html tags:

<p><span class = 'StockHint StockHint_InStock'>
In Stock: 68</span></p>

Please, how do I cut down this massive string to just this stock number??

Thanks :D

fixdreamer
New php-forum User
New php-forum User
Posts: 10
Joined: Tue Dec 13, 2011 3:29 pm

Re: Using External Site Information

Postby fixdreamer » Mon Jan 21, 2013 3:57 pm

Hi, If anyone is interested I managed to solve this by using simple html dom parser.

<?php

//include dom script

include './simple_html_dom.php';

// Create DOM from URL or file

$html = file_get_html('site-address.com/item-description3637');


// Find all <span> with the id attribute
$ret = $html->find('span[class="StockHint StockHint_InStock"]');

$stock = $ret[0];

//make stock an int

$stock_number = preg_replace("/[^0-9]/", '', $stock); // ditch anything that is not a number

if ($stock == NULL){
$stock = "Sorry, Out Of Stock!";
$stock_number = 0;
}

echo $stock;

echo "<br/><br/>";

echo $stock_number;

:D

satalways
New php-forum User
New php-forum User
Posts: 5
Joined: Thu Jan 24, 2013 6:39 am
Location: Lahore, Pakistan
Contact:

Re: Using External Site Information

Postby satalways » Thu Jan 24, 2013 7:03 am

or you can use simple codes

Code: Select all

$suppliers_page = file_get_contents('http://www.their-website.com/product-234-page.aspx');
$suppliers_page=strip_tags($suppliers_page);
echo $suppliers_page;


Return to “PHP General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest