RE: [PHP] Everything between something becomes an array element
| From: | ArsenKirillov | Date: | Mon, 12 Nov 2001 08:20:51 +0000 |
| Subject: | RE: [PHP] Everything between something becomes an array element | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-74237@lists.php.net to get a copy of this message | ||
U question was :
Everything __between something___ becomes an array element
What is wrong with answer :
tag[1]=
<td><table><tr><td>foo</td><td>bar</td></tr></table>
tag[2]= <td>foo</td><td>bar</td>
:-)))
AK>-----Original Message-----
AK>From: Andrey Hristov [mailto:andy@icygen.com]
AK>Sent: Tuesday, November 06, 2001 5:18 PM
AK>To: softm@ipm.lviv.ua
AK>Cc: php-general@lists.php.net
AK>Subject: Re: [PHP] Everything between something becomes an array element
AK>
AK>
AK>But .... watch this...
AK><body>
AK><table><tr><td><table><tr><td>foo</td><td>bar</td></tr></table></
AK>tr></table>
AK><table><tr><td>foo bar</td></tr></table>
AK></body>
AK>
AK>I think that the return result will be
AK><tr><td><table><tr><td>foo</td><td>bar</td></tr></table></tr></table>
AK><table><tr><td>foo bar</td></tr>
AK>
AK>Why? Beacuse you set PCRE to be greedy. I think that there is no
AK>easy way to
AK>solve the problem with nested <tr> tags.
AK>
AK>Regards,
AK>
AK>Andrey Hristov
AK>Web Developer
AK>Icygen Corporation
AK>BUILDING SOLUTIONS
AK>http://www.icygen.com
AK>
AK>
AK>On Tuesday 06 November 2001 02:57 am, you wrote:
AK>> Here is right implememtation of all i see
AK>>
AK>> <?
AK>> $co=0;
AK>>
AK>> $str="<tr><td><table><tr><td>foo</td><td>bar</td></tr></table></tr>";
AK>> echo "<pre>";
AK>> GetTagElements($str);
AK>> echo "</pre>";
AK>>
AK>> function GetTagElements($str)
AK>> {
AK>> global $co;
AK>> if ($co++){echo "tag[".($co-1)."]=
AK>> ".htmlentities($str)."<br>";}
AK>>
AK>>
AK>>
AK>$how=preg_match_all('~\<tr\>(.*)<\/tr\>~',$str,$var_match,PREG_SE
AK>T_ORDER);
AK>> if ($how)
AK>> for ($i=1;$i<count($vr=$var_match[0]);$i++)
AK>> {
AK>> GetTagElements($vr[$i]);
AK>> }
AK>> else return 0;
AK>> }
AK>>
AK>> ?>
AK>>
AK>> > -----Original Message-----
AK>> > From: Andrey Hristov [mailto:andy@icygen.com]
AK>> > Sent: Monday, November 05, 2001 11:13 PM
AK>> > To: php-general@lists.php.net
AK>> > Subject: Re: [PHP] Everything between something becomes an
AK>array element
AK>> >
AK>> >
AK>> > Sorry
AK>> >
AK>> >
AK>> > $how=preg_match_all('|\<tr>(.*?)</tr\>|',$the_big_string,$matches,
AK>> > PREG_SET_O
AK>> > RDER);
AK>> >
AK>> > is the correct I think
AK>> >
AK>> > Excuses
AK>> >
AK>> > On Monday 05 November 2001 08:57 am, you wrote:
AK>> > > It gives me an error....:
AK>> > >
AK>> > > Warning: Compilation failed: nothing to repeat at offset 7 in
AK>> > > c:\www\innocenti\teste.php on line 17
AK>> > >
AK>> > > I think that 'offset' is like a letter from the regex, but I
AK>> >
AK>> > could not fix
AK>> >
AK>> > > it...
AK>
AK>--
AK>
AK>--
AK>PHP General Mailing List (http://www.php.net/)
AK>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
AK>For additional commands, e-mail: php-general-help@lists.php.net
AK>To contact the list administrators, e-mail: php-list-admin@lists.php.net
AK>