What's the best way to get content from an external website via php?
Using php how do I go to webpage (ex: http://store.domain.com/1/) and scan the HTML coding for data that is found in between (which is the letter C and E). what php method do I use?
C
E
then save "C" (the found string) to $pname
$_session['pname1'] = $pname1;
$_session['pname2'] = $pname2;
Answer
The most efficient method is:
$content = file_get_contents('http://www.domain.com/whatever.html');
$pos = str_pos($content,'id="c');
$on=0;
while($pos!==false)
{
$content = substr($content,$pos+4);
$pos = str_pos($content,'"');
$list[$on] = substr($content,0,$pos);
$on++;
$pos = str_pos($content,'id="c');
}
Then all yours values will be in the $list array, the count of which is $on.
You could also do it in one line with one of the preg functions, but I like the old-school method, it's a nanosecond faster.
No comments:
Post a Comment