-1

i can get text from tags between </a></div> and <div class="toolz">. in result of that i have img tag with <br /> after that.

for example:

<img alt="TEXT" title="TEXT"src="IMAGE LINK" /><br />

how to remove from that with preg_replace?

<meta charset='UTF-8' />
<?php
    $handle='http://www.namefa.ir/Names.asp?pn=4&sx=M&fc=%D8%A2';
    preg_match_all('/<\/a><\/div>(.*?)\s*<div[^>]+class="toolz"[^>]*>\s*/si', file_get_contents($handle), $matching_data);
    $default = preg_replace('/<img[^>]*>(.*)\/><br />/is', "", $matching_data);
    echo'<pre>';print_r($default);echo'</pre>';
?>
DolDurma
  • 15,753
  • 51
  • 198
  • 377

1 Answers1

1

I think, you code has some logical mistakes.. you have to use an loop to iterate through your search results and replace the tags in your original content. What you do now, seems a little bit useless.

$handle='http://www.namefa.ir/Names.asp?pn=4&sx=M&fc=%D8%A2';
$content = file_get_contents($handle);
preg_match_all('/<\/a><\/div>(.*?)\s*<div[^>]+class="toolz"[^>]*>\s*/si', $content, $matching_data, PREG_SET_ORDER);
foreach ($matching_data as $match) {
    $replace = preg_replace('/<img[^>]*>(.*)\/><br />/is', "", $match[0]);
    $content = str_replace($matching_data[0], $replace, $content);
}
echo'<pre>';print_r($content);echo'</pre>';

It seems your inner regex to replace the image is wrong.. at least it doesn't find something - are you sure, the <br /> is correct, or if you just want to find a simple line break

Philipp
  • 15,377
  • 4
  • 35
  • 52