Announcement

Collapse
No announcement yet.

Pull text from HTML.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pull text from HTML.

    Hey guys and gals,

    I am looking for the code to pull words from the source of my HTML pages. I used to have something that did this in ASP but I can not find it anywhere. I am sure it is just as easy to do in PHP only I am dumb founded. It was a page with a text box that I copied my html source into and when I hit sumbit it would extract the words I was looking for.

    Example: I want to search for the letters bullet and in the html it had "vbulletin, bullet holes, and large bullets". The script would pull out any instance of the word bullet including the entire word so from the above it would grab:

    vbulletin
    bullet
    bullets

    I know this can be done but I can figure it out. Any help would be greatly appreciated. Thanks in advance...

    David Smith

  • #2
    Anyone know this?

    Comment


    • #3
      tested
      PHP Code:
      <?php

      // http://www.vbulletin.com/forum/newreply.php?s=&action=newreply&threadid=42254


      $string=<<<myHTML
      This is a sentence about vBulletin.
      There are no bullet wholes in vBulletin.
      And so, you will find no smoking gun or big bullets.

      myHTML;


      echo 
      "<html><body><pre>\n";

      $find "bullet";
      $tmp preg_match_all("#\\W(\\w*" $find "\\w*)\\W#Ui"$string$match);

      for (
      $i=0$i<count($match[0]); $i++) {
          echo 
      $match[1][$i] . "\n";
      }

      echo 
      "</pre></body></html>";

      ?>
      Output:
      Code:
      vBulletin
      bullet
      vBulletin
      bullets
      This will work for most things. It may need tweaked if you start searching for things other than words, as I'm using word boundries to define what to return.

      Comment

      Related Topics

      Collapse

      Working...
      X