regex - How to use PHP to echo entire word with occurance of character sequence? -


i have php scraper scrapes urls , echos out material inside given div. want modify scraper check html on page occurence of string, , echo out entire word string occurs in.

my current scraper this:

<?php $urls = array(  "http://www.sample1.html", "http://www.sample2.html", "http://www.sample3.html", ); foreach($urls $url){ $content = file_get_contents($url); $first_step = explode( '<div class="div1">' , $content ); $second_step = explode("</div>" , $first_step[1] ); echo $second_step[0]."<br>"; }; ?> 

i want more this, working:

$first_step = explode( 'eac' , $content ); 

with results being:

  1. teacher
  2. preacher
  3. each etc...

you can use following regex preg_match instead of explode:

(\w*eac\w*) 

code:

preg_match('(\w*eac\w*)', $content , $first_step , preg_offset_capture); echo $first_step[1]; 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -