Try to solve an HTML problem with a regular expression, and soon you have two problems.
But if you really want to do this with a dirty regular expression, it can be done. You shouldn’t rely on it. The simplest regex is something like:
preg_match_all(
"/<td class=bilgi_satir width=\"..%\"><b>(.*)<\/b>/i",
$your_html_here, $m
);
This returns roughly what you want with print_r( $m[1] );
(I added 1, 2, 3 to tell ’em apart)
Array (
[0] => ( PLACE I WANT TO FETCH 1 )
[1] => ( PLACE I WANT TO FETCH 2 )
[2] => ( PLACE I WANT TO FETCH 3 )
)
Best way to do this is with DOM parsing. For example:
$doc = new DOMDocument();
$doc->loadHTML( $your_html_here );
$x = new DOMXPath( $doc );
$results = $x->query("//td[@class="bilgi_satir"]//b");
# $results->length now shows 3
$ret = array();
foreach( $results as $count => $result ) {
printf( "item # %s = %s\n", $count, $result->nodeValue ); # debug only
$ret[] = $result->nodeValue;
}
This will display:
item # 0 = ( PLACE I WANT TO FETCH 1)
item # 1 = ( PLACE I WANT TO FETCH 2)
item # 2 = ( PLACE I WANT TO FETCH 3)
Edit: obviously dumping the node value into an array lets you access via array, as you wanted.
1
solved Php Preg Match, how can i do this [closed]