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 9240103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:07:54+00:00 2026-06-18T08:07:54+00:00

I’m trying to pull in an element from an external website using PHP and

  • 0

I’m trying to pull in an element from an external website using PHP and cURL.

  • The link to the website I’m trying to pull content from is:
    http://www.stayclassy.org/fundraise?fcid=231864

  • The element I’m targeting is the number value under the list item
    “Raised So Far” in the right column at the top (right now the value is at $10).

  • Here is the code I’m using to extract the data:

        define("TARGET", "http://www.stayclassy.org/fundraise?fcid=231864");

    $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, TARGET); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if(!($results = curl_exec($curl))) { print("{ \"total\": \"$0.00\" }"); return; } $pattern = '/\<li class="goalTitle"\> \$(.+?) \<\/li\>\<\/a\>/'; preg_match_all($pattern, $results, $matches); $total = $matches[1][0]; $total = str_replace(",", "", $total); printf("{ \"total\": \"$%s\" }", formatMoney($total, true)); function formatMoney($number, $fractional=false) { if ($fractional) { $number = sprintf('%.2f', $number); } while (true) { $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number); if ($replaced != $number) { $number = $replaced; } else { break; } } return $number; }

The issue I’m having is that the list item/element I’m targeting doesn’t have a unique ID or class. In fact, the dollar amount is located in a separate list item without a class.

I was wondering how to target a specific list item in an unordered list using the code above, particularly when it doesn’t have a class. Any ideas?

  • 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-06-18T08:07:55+00:00Added an answer on June 18, 2026 at 8:07 am

    Targeting the specific item requires that you identify a unique string around it. To do this you just expand further and further out until you find a string you can identify that only occurs once. So, the line you want is:

    <li>$10</li>
    

    but this is not unique at all. So we expand the string by adding the previous line as well:

    <li class="goalTitle">Raised so far:</li>
    <li>$10</li>
    

    and bingo, this string is unique for your needs. The string is fairly constant except for your amount, so it will be easy to use. So you need a regular expression that finds this string. I’d use something like this:

    $pattern = '/<li class="goalTitle">Raised so far:<\/li>\s*<li>\$(\d+)<\/li>/';
    

    You don’t need to use preg_match_all because you only expect to get one match:

    preg_match($pattern, $results, $matches);
    $total = $matches[1];
    

    Your other options include loading the page with a DOMDocument, and then using XPath or getElementById to parse the DOM. But that may be a little too much effort for this task.

    Also, I’d use file_get_contents to fetch the contents of the remote site. But that’s just me.


    UPDATE: To handle thousands separators as well, modify your pattern as follows:

    $pattern = '/<li class="goalTitle">Raised so far:<\/li>\s*<li>\$([\d\.,]+)<\/li>/';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.