Jump to content

[SOLVED] Help with regex


therealwesfoster

Recommended Posts

When I run a preg_match, and there are multiple </b> (where i want the regex to stop), how can I make it stop at the NEXT occurrence? Sometimes it skips all the way to the last occurrence, or somewhere in between. IE:

 

 

Here's my sample code:

<h2>
<i>
<div>
  <b>
   <i id="2">My text!</i>
  </b>
</div>
</i>
</h2>

 

And my regex: (this is a quick throw-together.. non tested. just to help me ask my question)

 

<?php
$string = file_get_contents("THE_ABOVE_CODE");

$body = preg_match('/\<i id="2">(.*)\<\/i>/ism',$string,$match);

echo "<pre>".print_r($match)."</pre>";
?>

 

Now in the code, instead of selecting the </i> right after the text "My Text!", it selects the last </i> in the script... why?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/106053-solved-help-with-regex/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.