php problem

Discussion in 'PHP' started by ssimon171078, Sep 6, 2014.

  1. #1
    i want to receive text from html ,i received html page and i want to extract from this page text file how can i change this code:

    <?php
    $page = file_get_contents(' website');
    $fh=fopen("file1.txt","a");
    fwrite($fh,$page);
    fclose($fh);
    
    ?>
    Code (markup):
     
    ssimon171078, Sep 6, 2014 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Could you explain your question in English?
     
    deathshadow, Sep 6, 2014 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Also, if you cast a slight glance upwards when you enter "programming" in the forum list, you'll see there's a "php" - forum, for (gasp!) php related questions
     
    PoPSiCLe, Sep 9, 2014 IP
  4. ssimon171078

    ssimon171078 Well-Known Member

    Messages:
    277
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    i have this html code:
    <h4 class="h4bit"><a href="https://www.seoclerk.com/Social-Networks/10394/promote-any-url-on-30-Million-FB-groups-OR-99-PR-9-Search-Engine-Indexing" class="listbit">promote any <span>url</span> on 30 Million FB groups OR, 99 PR 9 Sear... for $10</a></h4>

    i need to receive text:https://www.seoclerk.com/Social-Networks/10394/promote-any-url-on-30-Million-FB-groups-OR-99-PR-9-Search-Engine-Indexing

    i need to filter html tags this my question
     
    ssimon171078, Sep 9, 2014 IP
  5. donjajo

    donjajo Active Member

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    51
    #5
    PHP DOMDocument does that, read more - http://php.net/manual/en/class.domdocument.php
     
    donjajo, Sep 9, 2014 IP
  6. thaiweelchair

    thaiweelchair Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #7
    I think this function can help you

    <?php function getArray($node)
    {
       $array = false;
    
        if ($node->hasAttributes())
        {
            foreach ($node->attributes as $attr)
            {
               $array[$attr->nodeName] = $attr->nodeValue;
            }
        }
    
        if ($node->hasChildNodes())
        {
            if ($node->childNodes->length == 1)
            {
               $array[$node->firstChild->nodeName] = $node->firstChild->nodeValue;
            }
            else
            {
                foreach ($node->childNodes as $childNode)
                {
                    if ($childNode->nodeType != XML_TEXT_NODE)
                    {
                       $array[$childNode->nodeName][] = $this->getArray($childNode);
                    }
                }
            }
        }
    
        return $array;
    } ?>
    PHP:
     
    thaiweelchair, Sep 14, 2014 IP
  7. YoGem

    YoGem Active Member

    Messages:
    676
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    90
    #7
    While DOM can be the answer, simple scraping can be done with preg_match:

    //I assume you need the class..
    $pattern = "/<a href=\"(.*)\" class=\"listbit\">/siU"
    preg_match_all($pattern,$string,$results);
    print_r($results[1]);
    PHP:
     
    YoGem, Sep 22, 2014 IP