Answer the question
In order to leave comments, you need to log in
How to parse a forum post using PHP Simple HTML DOM Parser?
I need help, I need to parse the text of messages from a forum thread of only 1 author.
For example, from the forum
only the author "sakakolm"
Answer the question
In order to leave comments, you need to log in
I would advise you to look in the direction of phpQuery, especially if you have ever worked with jQuery
Only I was too lazy to play with the encoding, but I think this will no longer be a problem :)
<?
require_once 'phpQuery.php';
$url = 'http://ruforum.mt5.com/threads/2494-obzor-valyutnogo-rinka-za-nedelyu';
$userName = 'almostsuper';
$htmlPage = file_get_contents($url);
$html = phpQuery::newDocument($htmlPage);
$posts = $html->find('.postdetails');
foreach ($posts as $var) {
$userPost = pq($var)->find('.username > strong:contains('.$userName.')');
if($userPost->text()==$userName)
{
echo '<h1>'.$userName.'</h1>';
$postBody = pq($var)->find('.postbody');
echo $postBody.'<hr/>';
}
}
look for an example of using dom parser.
Or say what is the problem that served to write the question here.
I can't set a regular expression to parse a message with the id= user condition
One expression is not enough here. Something like this:
$rows = $html->find('ol#posts > li > div.postdetails > div.userinfo > div.username_container > div > a.username[href*=3606-sakakolm]');
foreach($rows as $row) {
$msg_html = $row->parent()->parent()->parent()->next()->find('div.postrow > div.content');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question