Click here to Skip to main content
15,881,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me with this. I am not a good in explaining and my grammar is not that good so please bear with me.

My client wants a website which auto search a manufacturing part number from a certain website.

http://www.digipart.com/

The code for the auto search is working and there's no error. However, my client wants to check for each manufacturing part number which is saved from database if it have a search result here is my code:

<pre lang="PHP">
$searchmfgpn =@mysql_query("select mfg_pn from bom_crunching; ");
//@mysql_query($searchmfgpn,$connect)or die("Failed to execute query:<br />" . mysql_error(). "<br />" . mysql_errno());
while($row = mysql_fetch_array($searchmfgpn))
{
    $searchkeyword =$row['mfg_pn'];
    echo $searchkeyword;    
    $digipart ="http://www.digipart.com/part/".$searchkeyword;
    //echo "<iframe src=".$digipart." width ='1200' height ='600'></iframe>";
    $string = "We are sorry, but no result was found for '$searchkeyword' Please try again."; 

    if (strpos($digipart,$string) !== false) {
    echo 'Not Available.';
    } else {
    echo 'Available';
    }

}

the code didn't gave me any errors, however the code I used to check if it is available or not is incorrect. It only check for the URL. I want to check for the whole page, which is I don't know what code should I use.

How can I fixed this? Any help will be appreciated!!
Posted

1 solution

You could try this (if you want to search the whole page content) :


PHP
// your code....
$digipart ="http://www.digipart.com/part/".$searchkeyword;
$pageContent = getHtml($digipart);

if (strpos($pageContent, $string) !== false) {
    echo 'Not Available.';
} else {
    echo 'Available';
}

function getHtml($url, $post = null) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    if(!empty($post)) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }

    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
 
Share this answer
 
v4
Comments
Member 11853731 22-Jul-15 2:06am    
hey @Prava-MFS I tried your code but unfortunately the file_get_contents is not working :(((
Prava-MFS 22-Jul-15 2:10am    
Try the updated code and let me know if it worked for you.
Member 11853731 22-Jul-15 4:11am    
Hi thanks for the effort, but it still doesn't work for me :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900