Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Cadish on October 14, 2003, 09:54:49 AM

Title: Get string out of another string
Post by: Cadish on October 14, 2003, 09:54:49 AM
I have a page, and there are lines in the code like this:

<td width="85%" class="txt">THIS</td>
<td width="85%" class="txt">THAT</td>
<td width="85%" class="txt">THERE</td>
<td width="85%" class="txt">ALWAYS</td>
<td width="85%" class="txt">NEVER</td>

How can i put the words 'THIS', 'THAT' , 'THERE', 'ALWAYS', 'NEVER' (they are always changing) into an array? I've tried with the command eregi, but that seems to be pretty hard to do...

Pls, can ya help me?
Thx a lot!!
Title: Re:Get string out of another string
Post by: chris on October 14, 2003, 09:59:17 AM
<?php

   $dummy      
'<td width="85%" class="txt">THIS</td>
<td width="85%" class="txt">THAT</td>
<td width="85%" class="txt">THERE</td>
<td width="85%" class="txt">ALWAYS</td>
<td width="85%" class="txt">NEVER</td>'
;

   
$pattern   '#<td width="85%" class="txt">(.+?)</td>#';
   
   echo 
'<pre>';
   if (
preg_match_all($pattern,$dummy,$matches))
      
print_r($matches);
   echo 
'</pre>';

?>
Title: Re:Get string out of another string
Post by: Cadish on October 14, 2003, 10:01:31 AM
Thanks a lot!!

I will give this a try...
Title: Re:Get string out of another string
Post by: Cadish on October 14, 2003, 10:23:20 AM
Ok, this works fine,
but sometimes the code is like this, so he doesn't add this into the string...

<td width="85%" class="txt">THIS</td>
<td width="85%" class="txt">TH
AT</td>
<td width="85%" class="txt">THERE</td>
<td width="85%" class="txt">ALWAYS</td>
<td width="85%" class="txt">NEVER</td>
Title: Re:Get string out of another string
Post by: chris on October 14, 2003, 10:44:49 AM
Replace

$pattern   = '#<td width="85%" class="txt">(.+?)</td>#';

with

$pattern   = '#<td width="85%" class="txt">(.+?)</td>#s';

and it works for multiple lines, too...