Get Specific Contents from WebPage?

Discussion in 'PHP' started by gerard0986, Apr 24, 2010.

  1. #1
    How would I use PHP to got to a specific URL, and get a specific part of it to display?

    Like I want only this part:
    [​IMG]

    out of:
    http://jisho.org/words?jap=ganguro&eng=&dict=edict

    It also has to be able to get other words if I decide to search for a different word.
     
    gerard0986, Apr 24, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <?php
    header('Content-Type: text/html;charset=utf-8');
    
    //the word to find...
    $word = 'ganguro';
    
    preg_match('~<td class="kanji_column">(.+?)</tr>~s', file_get_contents('http://jisho.org/words?jap='.$word.'&eng=&dict=edict'), $a);
    
    //now you can add css/styles etc. to the output if need be
    echo strip_tags($a[1]);
    
    ?>
    PHP:
     
    danx10, Apr 24, 2010 IP
  3. gerard0986

    gerard0986 Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    danx10, Apr 24, 2010 IP
  5. gerard0986

    gerard0986 Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    gerard0986, Apr 24, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    <?php
    header('Content-Type: text/html;charset=utf-8');
    
    //the word to find...
    $word = 'sekai';
    
    preg_match_all('~<td class="kanji_column">(.+?)</tr>~s', file_get_contents('http://jisho.org/words?jap='.$word.'&eng=&dict=edict'), $a);
    
    foreach($a[1] as $result){
    echo strip_tags($result)."<br>";
    }
    
    ?>
    PHP:
     
    danx10, Apr 24, 2010 IP
  7. gerard0986

    gerard0986 Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    How would I go about "styling" the output?
     
    gerard0986, Apr 24, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    <?php
    header('Content-Type: text/html;charset=utf-8');
    
    //the word to find...
    $word = 'sekai';
    
    preg_match_all('~<td class="kanji_column">(.+?)</tr>~s', file_get_contents('http://jisho.org/words?jap='.$word.'&eng=&dict=edict'), $a);
    
    foreach($a[1] as $result){
    echo "<div class=\"output\">".strip_tags($result)."</div><br>";
    }
    
    ?>
    <style type="text/css">
    .output { 
    color: blue; 
    background-color: #d8da3d;
    }
    </style>
    PHP:
    Custimize the css, a basic knowledge of css and html. Would help before jumping into php.

    http://www.w3schools.com/css/default.asp
     
    danx10, Apr 24, 2010 IP