Jump to content

Regex with possible multiple line breaks


freeloader

Recommended Posts

Hi guys,

 

I want to crawl through userprofiles on a site, but users have the possibility to use line breaks in their profile.

 

The profiles look like this:

 

<td class="box_content" align="center"><img src="/images/avatars/621/620232-45f783a37ad80.jpg"></td>

        </tr>
        <tr>
          <td class="box_content">Blablabla line 1<br />
<br />
Line 2<br />
<a href="http://www.google.be" target="_blank">Some link</a></td>

 

Which gives, of course, the following output:

 

Blablabla line 1

Line 2

Some link

 

When no line breaks are used, this is the source code:

 

          <td class="box_content" align="center"><img src="/images/avatars/644/bb6a0f2f4e868d418e652a585753f1b1.jpg"></td>

        </tr>
        <tr>
          <td class="box_content">Sitting around smoking my </td>

 

What I need to extract is the profile text (everything between TD tags), best of all would be if that was stripped from any other tags to save space.

 

My current RegEx to do this:

 

$a=preg_match("/\b<td class=\"box_content\">.*.\b.*.td>/i",$res,$d);

 

While this works fine when no line breaks are used, it doesn't work at all when line breaks are used.

 

I've tried solutions with variable line breaks in the RegEx (like: \n*), but couldn't come up with any solution.

 

Any help is welcome, thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/62178-regex-with-possible-multiple-line-breaks/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.