LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-20-2015, 09:14 AM   #1
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
PHP grab third tr in a td?


Here it is:

This is at http://localhost/address?queue=one, and I need a php script to curl that, search for 'super_section' and spit out the related number 123456789 from it:

Code:
  <tr class="odd">
                <td>server001</td>
                <td>super_section</td>
                <td class="ra">0</td>
                <td class="ra">0</td>
                <td class="ra">
                                        123456789                </td>
            </tr>
Anyone have a moment to churn out the PHP code to do this? Its appreciated.

Here is what I have..

Code:
<?php

function curl_download($Url){

    if (!function_exists('curl_init')){
        die('cURL is not installed. Install and try again.');
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);

    $start = strpos($output, '<td>super_section</td>');
    $end = strpos($output, ' </tr>', $start);
    $length = $end-$start;
    $output = substr($output, $start, $length);

    $start = strpos($output, '<td class="ra">');
    $end = strpos($output, ' </td>', $start);
    $length = $end-$start;
    $output = substr($output, $start, $length);


    return $output . "\n";
}


print curl_download('http://localhost/address?queue=one');

?>
Which gets me down to the text:

Code:
<td class="ra">0</td>
    <td class="ra">0</td>
    <td class="ra">
                                123456789

Last edited by szboardstretcher; 11-20-2015 at 09:28 AM.
 
Old 11-20-2015, 09:39 AM   #2
teapottwo
Member
 
Registered: Sep 2013
Posts: 52

Rep: Reputation: Disabled
You'd be better off using one of the preg functions...

http://php.net/manual/en/function.preg-match.php
 
Old 11-20-2015, 09:49 AM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Original Poster
Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Thanks for the reply. I was able to copy and paste to hack together some code for it faster than anyone could reply. Its usually the case that I ask for a quick bit of code to save myself time, and I end up being able to google and hack it together faster. I dont know why I bother - except that I enjoy talking to my people at LQ.

Code:
<?php

function curl_download($Url){

    if (!function_exists('curl_init')){
        die('cURL is not installed. Install and try again.');
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);

    $start = strpos($output, '<td>processimage_photoshop</td>');
    $end = strpos($output, ' </tr>', $start);
    $length = $end-$start;
    $output = substr($output, $start, $length);

    $start = strpos($output, '<td class="ra">');
    $end = strpos($output, ' </td>', $start);
    $length = $end-$start;
    $output = substr($output, $start, $length);

    $output = implode("\n", array_slice(explode("\n", $output), 3));
    $int = filter_var($output, FILTER_SANITIZE_NUMBER_INT);

    return $int . "\n";
}

print curl_download('http://localhost/queue.php?sort=name');

?>
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can i use php to grab remote image and display as if local whysyn Programming 4 03-29-2007 03:39 PM
Grab OS in PHP??? bfloeagle Programming 1 06-05-2004 06:37 PM
Need to grab bookmarks from IE... slackMeUp Linux - Software 3 01-25-2004 05:02 PM
Grab Cert?? joseph_1970 Linux - General 6 12-17-2003 09:39 AM
xv grab garbage kramtoad Linux - Software 0 08-23-2003 07:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration