Get HTML TAG once
Posted: Mon Oct 24, 2005 8:59 am
I have a string like this:
$str = "<tbody>more tags A</tbody>
<tbody>more tags B</tbody>
<tbody>more tags C</tbody>
<tbody>more tags D</tbody>";
Then i want to use reg ex to only get the first <tbody>more tags A</tbody>. How do i do that?
I have tried these regular expressions:
-----------------------------------------------------
eregi("(<tbody[^>]*>(.*)</tbody>){1}", $str, $tBodys); // <-- you get all tbodys, but it should be only once, look at {1}
eregi("(<tbody[^>]*>(.*)</tbody>)", $str, $tBodys); // <-- you get all tbodys
$tBody = $tBodys[0];
echo $tBody;
$str = "<tbody>more tags A</tbody>
<tbody>more tags B</tbody>
<tbody>more tags C</tbody>
<tbody>more tags D</tbody>";
Then i want to use reg ex to only get the first <tbody>more tags A</tbody>. How do i do that?
I have tried these regular expressions:
-----------------------------------------------------
eregi("(<tbody[^>]*>(.*)</tbody>){1}", $str, $tBodys); // <-- you get all tbodys, but it should be only once, look at {1}
eregi("(<tbody[^>]*>(.*)</tbody>)", $str, $tBodys); // <-- you get all tbodys
$tBody = $tBodys[0];
echo $tBody;