Jump to content
Sign in to follow this  
subhomoy

need help in regex

Recommended Posts

hello every body,

 

Currently i'm scraping web data for a demo project but i cant preg_match the value from this html.

The html code is 
 

<div class="carouselContainer leftDisabled">
                    <ul class="carousel leftDisabled">
                            <li>
                                <div class="thumbContainer">
                                    <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzb4ywyj25mw4.jpeg)"
                                         data-imageId="IMADZB4YWYJ25MW4">
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div class="thumbContainer">
                                    <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzb4zhk4855ny.jpeg)"
                                         data-imageId="IMADZB4ZHK4855NY">
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div class="thumbContainer">
                                    <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzwrpmdwhnxg7.jpeg)"
                                         data-imageId="IMADZWRPMDWHNXG7">
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div class="thumbContainer">
                                    <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzwvvz3deeh4c.jpeg)"
                                         data-imageId="IMADZWVVZ3DEEH4C">
                                    </div>
                                </div>
                            </li>
                    </ul>
            </div>

The regex i've used is

preg_match_all('|<div class="carouselContainer leftDisabled"+>(.*)</div+>|U',$txt,$matches3);

I want only the images images url from that specific block.

 

Can anybody help me in this plz...

Share this post


Link to post
Share on other sites

Don't use regex for parsing HTML. Instead you should query the DOM to retrieve the content you want from a HTML element on a webpage.

 

You may find using simplehtmldom a lot simpler to use, it uses jquery like syntax for querying the DOM.

Share this post


Link to post
Share on other sites
I want only the images images url from that specific block.

 

 

if you only want the images from the that block , you can use this pattern

#background-image:url\((.*?)\)"#

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • 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.