My code is this <?php /* ** htmlSQL - Example 5 */ include_once("snoopy.class.php"); include_once("htmlsql.class.php"); $wsql = new htmlsql(); // connect to a URL if (!$wsql->connect('url', 'http://example.com/whatever/index.php')){ print 'Error while connecting: ' . $wsql->error; exit; } $wsql->isolate_content('<div class="cbox wt all">', '<ul class="pg">'); $test = $wsql->page; /* i need only the first parth which ends at 3th <li> */ print $test; ?> PHP: Here i'm getting a page which has many <li>s. I want to remove everything after 3th <li> Any ideas? Edited: By the way I know how to count <li>s but I do not know how I will save the part until 3th <li>