Jump to content
php.lv forumi

Preg_match


capsx

Recommended Posts

preg_match('/<td>(.*)</td>/i',$filevar,$blocks);

 

ja ir vairaaki <td>1</td><td>2</td><td>3</td> utt

 

kaa lai atgriezh tikai pirmo <td>1</td> nevis <td>1</td><td>2</td><td>3</td> ?

Link to comment
Share on other sites

  • 1 year later...

teksts satur:

<p><table class="main" border="0" cellspacing="0" cellpadding="0"><tr><td class="embedded"><h1 style="margin:0px">username<img src="bilde.gif" alt="nosaukums" style="border:0; margin-left:4pt" /></h1></td></tr></table></p>

vajag izlobīt "username",

rakstu šādi, bet nekas nesanāk.

preg_match("/<h1 style=\"margin:0px\">([^<]*)<",$text,$matches);

Link to comment
Share on other sites

radās vēlviena aizķeršanās. lapa satur:

[avatar=adrese.png]affa<br />

aaaa<br />

bbb<br />

[/avatar]

vajag piepildīt array ar vērtībām: array[0]='affa' array[1]='aaaa' utt

Edit:

ir doma ar šo /\[avatar.*](.*<br \/>\r\n)*\[\/avatar]/ izlobīt visu "[avatar=...]un ar visu kas ieksā[/avatar]", tad to stringu apstrādāt, varbūt ir cita iespēja?

Edited by loderis
Link to comment
Share on other sites

<?php
  $txt = "[avatar=adrese.png]affa<br />\naaaa<br />\nbbb<br />\n[/avatar]";

  $array = array();

  $t = "[avatar=adrese.png]";
  $p1 = strpos($txt, $t);
  $p2 = strpos($txt, "[/avatar]");
  $txt = substr($txt, $p1+strlen($t), $p2-$p1-strlen($t));

  if (preg_match_all('@([^<]+)\<br /\>'."\n".'?@m', $txt, $matches)) {
    for ($i=0; $i<count($matches[1]); $i++) {
      $array[] = $matches[1][$i];
    }
  }
  print_r($array);
?>

Link to comment
Share on other sites

×
×
  • Create New...