Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:23:12+00:00 2026-05-22T15:23:12+00:00

Hi i want to retrieve certain information from a website. This is what is

  • 0

Hi i want to retrieve certain information from a website.

This is what is display on the website with html tags.

    <a href="ProductDisplay?catalogId=10051&amp;storeId=90001&amp;productId=258033&amp;langId=-1" id="WC_CatalogSearchResultDisplay_Link_6_3" class="s_result_name">

                                                                SALT - Fine
</a>

What i want to extract is “SALT – FINE” using preg match however i do not know why i cant use it. isit because they are all on different line? cos i realise if they are on a single line i can actually retrieve what i want.

This is my code –

$pattern = '/id="WC_CatalogSearchResultDisplay_Link_6_3.*<\/a>/';
preg_match_all($pattern, $response, $match);
print_r($match);

I do not get anything in my array. if they are on a single line it works?.why is that so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:23:13+00:00Added an answer on May 22, 2026 at 3:23 pm

    Have a look at:

    http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

    especially the m and s modifiers.

    Also, I would recommend, changing the pattern to something like:

    $pattern = '/id="WC_CatalogSearchResultDisplay_Link_6_3"[^>]*>(.*)<\/a>/ims';
    

    Otherwise, you’ll match the end of your a-tag.

    And on a side note, don’t use regex to parse html/xml.

    Something like this:

    <?php
    $dom = DOMDocument::loadHtml($response);
    $xpath = new DOMXPath($dom);
    
    $node = $xpath->query('//*[@id="WC_CatalogSearchResultDisplay_Link_6_3"]/text()')->item(0);
    if ($node instanceof DOMText) {
        echo trim($node->nodeValue);
    }
    

    will also work, and will be a lot more robust.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML table as follows. I want retrieve row values from this
I want to retrieve website title from webview cookies of my application. I am
I want to make an application that will grab the HTML from a website
I want to collect certain information from people/devices via email. These emails will never
There is a web page from which I want to retrieve a certain string.
I want to retrieve all ids within a certain timespan. The timestamps however, are
I want applications to share certain database data. I want one application to retrieve
Using udev I have been able to get this information for a certain USB
I'm using ajax calls to retrieve some HTML data. In certain cases, there are
I am looking for some advice on the best way to retrieve information from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.