Advertisement:

Author Topic: Get string out of another string  (Read 3199 times)

Offline Cadish

  • Full Member
  • ***
  • Posts: 493
  • Gender: Male
Get string out of another string
« on: October 14, 2003, 09:54:49 AM »
I have a page, and there are lines in the code like this:

Code: [Select]
<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!!

chris

  • Guest
Re:Get string out of another string
« Reply #1 on: October 14, 2003, 09:59:17 AM »
Code: [Select]
<?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;;

?>

Offline Cadish

  • Full Member
  • ***
  • Posts: 493
  • Gender: Male
Re:Get string out of another string
« Reply #2 on: October 14, 2003, 10:01:31 AM »
Thanks a lot!!

I will give this a try...

Offline Cadish

  • Full Member
  • ***
  • Posts: 493
  • Gender: Male
Re:Get string out of another string
« Reply #3 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...

Code: [Select]
<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>

chris

  • Guest
Re:Get string out of another string
« Reply #4 on: October 14, 2003, 10:44:49 AM »
Replace

Code: [Select]
$pattern   = '#<td width="85%" class="txt">(.+?)</td>#';
with

Code: [Select]
$pattern   = '#<td width="85%" class="txt">(.+?)</td>#s';
and it works for multiple lines, too...