General Community > Scripting Help

Get string out of another string

(1/1)

Cadish:
I have a page, and there are lines in the code like this:


--- Code: ---<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>
--- End code ---
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!!

chris:

--- Code: ---<?php

   $dummy      = &#39;<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>&#39;;

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

?>
--- End code ---

Cadish:
Thanks a lot!!

I will give this a try...

Cadish:
Ok, this works fine,
but sometimes the code is like this, so he doesn't add this into the string...


--- Code: ---<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>
--- End code ---

chris:
Replace


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

with


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

and it works for multiple lines, too...

Navigation

[0] Message Index

Go to full version