tisuchi tisuchi - 1 year ago 57
HTML Question

Want to copy a particular line of text from HTML by PHP

I want to grab html code from a web page and I want to take some specific number of lines from that html code. I am able to fetch all information from webpage but cannot do copy. How can I do so?

My code is-

$sourceURL = file($link);

$title = '';

foreach ($sourceURL as $value) {

if(strpos($value, '<h1 class="title') !== false){

//if it return true, wanna copy that line and store into $title variable.

} else {
echo "nothing";

Any clue, how to do so?

Answer Source

You can use external library e.g: http://simplehtmldom.sourceforge.net/

$html = new simple_html_dom();

$title = $html->find('h1[class=title]');