i'm trying to get the content between two tags with a condition.
So here is a example, i want to get all tr's but only the ones with /c in it.
example string:
<tr><td> /a </td></tr>
<tr><td> /b </td></tr>
<tr><td> /c </td></tr>
<tr><td> /d </td></tr>
using what i got so far i get all tr's
preg_match_all("/<tr.*<\/tr>/", $input_lines, $output_array);
what do i need to do to get this working?
thank you
preg_match_all("/<td>([^<]*/c[^<]*)<\/td>/", $input_lines, $output_array);
in other words: Whenever the regex will encounter <
without having found a /c
- it will fail.
if other html tags could be inside the td, you need to replace [^<]*
with .*?
.
<td>([^<]*/c[^<]*)<\/td>
Note: using .*?
can lead to unwanted, greedy results see this example:
<td>(.*?/c.*?)<\/td>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.