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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:58:49+00:00 2026-06-14T09:58:49+00:00

I am new to PHP. I want to write code to find the id

  • 0

I am new to PHP. I want to write code to find the id specified in the html code below, which is 1123. Can any one give me some idea?

<span class="miniprofile-container /companies/1123?miniprofile="
      data-tracking="NUS_CMPY_FOL-nhre"
      data-li-getjs="http://s.c.lnkd.licdn.com/scds/concat/common/js?h=dyt8o4nwtaujeutlgncuqe0dn&amp;fc=2">
    <strong>
        <a href="http://www.linkedin.com/nus-trk?trkact=viewCompanyProfile&pk=biz-overview-public&pp=1&poster=&uid=5674666402166894592&ut=NUS_UNIU_FOLLOW_CMPY&r=&f=0&url=http%3A%2F%2Fwww%2Elinkedin%2Ecom%2Fcompany%2F1123%3Ftrk%3DNUS_CMPY_FOL-nhre&urlhash=7qbc">
        Bank of America
        </a>
    </strong>
</span> has a new Project Manager

Note: I don’t need the content in the span class. I need the id in the span class name.

I tried the following:

$dom = new DOMDocument('1.0', 'UTF-8');
@$dom->loadHTML($html);
$xmlElements = simplexml_import_dom($dom);
$id = $xmlElements->xpath("//span [@class='miniprofile-container /companies/$data_id?miniprofile=']");

… but I don’t know how to proceed further.

  • 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-14T09:58:51+00:00Added an answer on June 14, 2026 at 9:58 am

    dependent of your need, you could do

    $matches = array();
    preg_match('|<span class="miniprofile-container /companies/(\d+)\?miniprofile|', $html, $matches);
    print_r($matches);
    

    this is a very trivial regex, but could serve as a first suggestion. If you want to go via DomDocument or simplexml, you mustn’t mix both like you did in your example.
    What is your preferred way, we can narrow this down then.

    //edit: pretty much what @fireeyedboy said, but this is what I just fiddled together:

    <?php
    $html = <<<EOD
    <html><head></head>
    <body>
    <span class="miniprofile-container /companies/1123?miniprofile="
          data-tracking="NUS_CMPY_FOL-nhre"
          data-li-getjs="http://s.c.lnkd.licdn.com/scds/concat/common/js?h=dyt8o4nwtaujeutlgncuqe0dn&amp;fc=2">
        <strong>
            <a href="#">
            Bank of America
            </a>
        </strong>
    </span> has a new Project Manager
    
    </body>
    </html>
    EOD;
    
    $domDocument = new DOMDocument('1.0', 'UTF-8');
    $domDocument->recover = TRUE;
    $domDocument->loadHTML($html);
    
    $xPath = new DOMXPath($domDocument);
    $relevantElements = $xPath->query('//span[contains(@class, "miniprofile-container")]');
    $foundId = NULL;
    foreach($relevantElements as $match) {
        $pregMatches = array();
        if (preg_match('|/companies/(\d+)\?miniprofile|', $match->getAttribute('class'), $pregMatches)) {
            if (isset($pregMatches[1])) {
                $foundId = $pregMatches[1];
                break;
            }
        };
    }
    
    echo $foundId;
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to .htaccess just want to write one rule which is
I am new to php curl, can you help me to write code for
I'm new to PHP and I want this code <option value= disabled=disabled>-------------</option> to be
I want to write a php script, which lists all the items in the
Hello there I am new to php and want to learn to write reusable
I want to upload an image in Zend-framework. In Application_Form_Test.php I write following code....
In PHP (since 5.2.0) I can write this code: //$t is timestamp of day
im new in PHP and I want to know about PHP Zend Framework. What
I am new to php. I want to have a form such as this:
I'm so new in php. I want to ask for decbin function in PHP

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.